Conditions plugin

15 years 2 months ago #23445 by p9939068
Replied by p9939068 on topic Re:Conditions plugin
This is a really great plugin, thanks mikko. However i noticed a critical proclem, that is it doesnt consider fields that are required.

Scenario:
A "conditioned" field is required, if and only if the "conditioning" field that triggered it was selected. eg, a user is required to choose the model of his car if he first selects himself as a driver

But because it was not triggered to appear, it remains irrelevant to the user, but yet when the user tries to submit, he was notified that the field is required.

The way to get around this (i assume) is to set the fields as not required in the admin backend. This is no good if the "conditioned" field is required like i mentioned.

So anyway, long story short, here's the fix:
go to conditions.php line 78-79 (or thereabouts) and replace it with:
[code:1] $ret.="\nshowHide(document.getElementsByName(prefix+'".($fields[$fieldN]->name).$fieldPostfix.
"')[0].parentNode.parentNode,node.value=='".$condition->value."' && node.checked!=false, '".$fields[$fieldN]->name.$fieldPostfix."');";
[/code:1]
and then to line 90 (or thereabouts) and replace it with:
[code:1] $init.="\nshowHide(inputs[input].parentNode.parentNode,tempObj.value=='".$condition->value."' && tempObj.checked!=false, '".$fields[$fieldN]->name.$fieldPostfix."');}";
[/code:1]

Now, go to funcs.js, search for the function showHide, and change the whole function code to this:
[code:1]function showHide(element, show, reqfield){
if (element.addEventListener){
element.style.visibility=((show)?'visible':'collapse');
document.getElementsByName(reqfield)[0].mosReq = ((show)?'1':'0');
}else{
element.style.display=((show)?'block':'none');
document.getElementsByName(reqfield)[0].mosReq = ((show)?'1':'0');
}
}
[/code:1]

After fixing these codes, your users will no longer be prompted to fill in fields that are not visible to him.
Note: this hack assumes all fields (that are visible to the user depending on his responds to "conditioning" fields) are required, so the fields must be set to required at the backend.


Mike Feng
Creator of SIMGallery, SIMAnswers, and ParaInvite
www.simbunch.com
twitter.com/simbunch

Please Log in to join the conversation.

15 years 2 months ago #23457 by p9939068
Replied by p9939068 on topic Re:Conditions plugin
i came across another problem. When the user edits his profile and changed a certain "conditioning" field, the "conditioned" field, which is supposed to disappear, retains the value and gets send into the database.

Example:
Driver? [yes/no] - conditioning field
Car Model [ford/mustang/toyota] - conditioned field

A user who was originally a driver had a ford as his car model. But say one day he stopped driving and changed the Driver field to [no]. the Car Model field disappeared, but the value still gets updated.

Here's the fix:

in plug_conditions/funcs.js, edit the showHide function so that it looks like this:
[code:1]function showHide(element, show, reqfield){
fieldvalue = document.getElementsByName(reqfield)[0].value;
if (element.addEventListener){
element.style.visibility=((show)?'visible':'collapse');
document.getElementsByName(reqfield)[0].mosReq = ((show)?'1':'0');
document.getElementsByName(reqfield)[0].value = ((show)?fieldvalue:'');
}else{
element.style.display=((show)?'block':'none');
document.getElementsByName(reqfield)[0].mosReq = ((show)?'1':'0');
document.getElementsByName(reqfield)[0].value = ((show)?fieldvalue:'');
}
}
[/code:1]

The problem with this is that CB does a serverside check to see if the field is required. You'll need to bypass that for all fields which are "conditioned". To do this, go to comprofiler.php and looks for the function userSave. Around line 600+ there is a for-loop. At the bottom of the for-loop is an if-statement:[code:1]if ($rowExtras->$field == "" && $rowFields[$i]->required == 1 && !in_array($rowFields[$i]->type, array("delimiter", "hidden"«»))) {[/code:1]Change this to:[code:1]if ($rowExtras->$field == "" && $rowFields[$i]->required == 1 && !in_array($rowFields[$i]->type, array("delimiter", "hidden"«»)) && !isset($rowFields[$i]->conditionid)) {[/code:1]


Mike Feng
Creator of SIMGallery, SIMAnswers, and ParaInvite
www.simbunch.com
twitter.com/simbunch

Please Log in to join the conversation.

15 years 2 months ago #25050 by Andrew998
Replied by Andrew998 on topic Re:Conditions plugin
Hi mikko

This plugin looks perfect for my project. Any chance your server will be up soon for the latrest version?

Thanks

Andrew

Please Log in to join the conversation.

15 years 2 months ago #25055 by mikko
Replied by mikko on topic Re:Conditions plugin
The server that I have is decomissioned permanently. I have a a development server, but cannot publish anything on that server. Please see the downloads of this site for the latest version.

mikko

Please Log in to join the conversation.

15 years 2 months ago #25056 by Andrew998
Replied by Andrew998 on topic Re:Conditions plugin
I have the latest version from the site thanks.

I'm a bit confused regarding the comprofiler.html.php hack. The details in this thread don't match the current file and I'm not sure if it is still needed. There is nothing in the download about it.

I can't get it working at the moment and it does look like it isn't initiated.

Thanks

Andrew

Please Log in to join the conversation.

15 years 2 months ago #25061 by mikko
Replied by mikko on topic Re:Conditions plugin
You need the hack. The details in this thread are most likely for cb 1.0, and you need to adapt those to 1.0.1

mikko

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.335 seconds

Facebook Twitter LinkedIn