Juergen Posted April 3, 2015 Share Posted April 3, 2015 Hello @ all, I use a checkbox field to show or hide other fields in my form in the backend. If the checkbox is checked then show the fields. If the checkbox is unchecked then hide the fields. Unfortunately it will only work if I add the following condition to a field which has the field dependency mycheckboxfieldname=0 but it doesnt work if I add mycheckboxfieldname=1 As far as I know the values of checkboxes are 0 and 1 (unchecked and checked) I have no idea why it doesnt work. This case also doesnt work mycheckboxfieldname!=0 I use the latest dev version and the input field dependencies with checkboxes have worked in the past, but now I have troubles. Has anyone an idea? Link to comment Share on other sites More sharing options...
horst Posted April 3, 2015 Share Posted April 3, 2015 I believe the CheckboxFields can have a different value than 1. When building Forms with the API I can set $field->value => 2, if I want or need it. You should check which value your Field really has when checked. Link to comment Share on other sites More sharing options...
LostKobrakai Posted April 3, 2015 Share Posted April 3, 2015 There were some changes recently to implement support for OR-Selectors. Could you please check if your console does log any javascript errors? I've just checked it in a installation of mine and it's working, so maybe there's something interfering. To check the suggestion of horst just inspect the checkbox with the dev tools to see it's "checked" value. <input type="checkbox" id="Inputfield_checkbox" class="FieldtypeCheckbox" name="checkbox" value="1"> Link to comment Share on other sites More sharing options...
Juergen Posted April 3, 2015 Author Share Posted April 3, 2015 Outputting the value in frontend shows 1 or 0 as expected. <?php echo $page->mycheckboxfieldname;?> The form is only an admin form to create content in the backend and there I am not able to change the values of the checkboxfield. Link to comment Share on other sites More sharing options...
Juergen Posted April 3, 2015 Author Share Posted April 3, 2015 Markups: 1) Checkbox not checked: <input id="Inputfield_socialnetworkactivation" class="FieldtypeCheckbox" name="socialnetworkactivation" value="1" type="checkbox"> 2) Checkbox checked: <input id="Inputfield_socialnetworkactivation" class="FieldtypeCheckbox" name="socialnetworkactivation" value="1" checked="checked" type="checkbox"> As you can see in the source code the value is always 1, the difference is only checked="checked" In the log files no entry! Link to comment Share on other sites More sharing options...
LostKobrakai Posted April 3, 2015 Share Posted April 3, 2015 Then please to to /wire/templates-admin/scripts/inputfields.js and enable DebugMode on top there. Also make sure debug mode in /site/config.php is enabled. This will print out lots of information about the dependency management in your console. If this does not help by itself please post the relevant parts here. 1 Link to comment Share on other sites More sharing options...
Juergen Posted April 3, 2015 Author Share Posted April 3, 2015 This is from the console: Checkbox is checked: JqueryC...s?v=183 (Zeile 2) ------------------------------------------------------------------- inputfi...s?v=13c (Zeile 20) Field "socialnetworksintro" detected a change to a dependency field! Beginning dependency checks... inputfi...s?v=13c (Zeile 20) ---- inputfi...s?v=13c (Zeile 20) Start Dependency 0 inputfi...s?v=13c (Zeile 20) Condition type: show inputfi...s?v=13c (Zeile 20) Field: socialnetworkactivation inputfi...s?v=13c (Zeile 20) Operator: = inputfi...s?v=13c (Zeile 20) Required value: 1 inputfi...s?v=13c (Zeile 20) Field socialnetworkactivation - Current value: 1 inputfi...s?v=13c (Zeile 20) Field socialnetworkactivation - Matched? YES inputfi...s?v=13c (Zeile 20) ---- inputfi...s?v=13c (Zeile 20) Determined that field "socialnetworksintro" should be visible. inputfi...s?v=13c (Zeile 20) Field is already visible. inputfi...s?v=13c (Zeile 20) ------------------------------------------------------------------- inputfi...s?v=13c (Zeile 20) Field "Inputfield_fieldset1" detected a change to a dependency field! Beginning dependency checks... inputfi...s?v=13c (Zeile 20) ---- inputfi...s?v=13c (Zeile 20) Start Dependency 0 inputfi...s?v=13c (Zeile 20) Condition type: show inputfi...s?v=13c (Zeile 20) Field: socialnetworkactivation inputfi...s?v=13c (Zeile 20) Operator: = inputfi...s?v=13c (Zeile 20) Required value: 0 inputfi...s?v=13c (Zeile 20) Field socialnetworkactivation - Current value: 1 inputfi...s?v=13c (Zeile 20) Field socialnetworkactivation - Matched? NO inputfi...s?v=13c (Zeile 20) ---- inputfi...s?v=13c (Zeile 20) Determined that field "Inputfield_fieldset1" should be hidden. inputfi...s?v=13c (Zeile 20) Field is now hidden. inputfi...s?v=13c (Zeile 20) 1 visibility changes were made. inputfi...s?v=13c (Zeile 20) InputfieldWindowResizeActions() Checkbox is not checked: JqueryC...s?v=183 (Zeile 2) ------------------------------------------------------------------- inputfi...s?v=13c (Zeile 20) Field "socialnetworksintro" detected a change to a dependency field! Beginning dependency checks... inputfi...s?v=13c (Zeile 20) ---- inputfi...s?v=13c (Zeile 20) Start Dependency 0 inputfi...s?v=13c (Zeile 20) Condition type: show inputfi...s?v=13c (Zeile 20) Field: socialnetworkactivation inputfi...s?v=13c (Zeile 20) Operator: = inputfi...s?v=13c (Zeile 20) Required value: 1 inputfi...s?v=13c (Zeile 20) Field socialnetworkactivation - Current value: 1 inputfi...s?v=13c (Zeile 20) Field socialnetworkactivation - Matched? YES inputfi...s?v=13c (Zeile 20) Field socialnetworkactivation - Current value: 0 inputfi...s?v=13c (Zeile 20) Field socialnetworkactivation - Matched? NO inputfi...s?v=13c (Zeile 20) ---- inputfi...s?v=13c (Zeile 20) Determined that field "socialnetworksintro" should be visible. inputfi...s?v=13c (Zeile 20) Field is already visible. inputfi...s?v=13c (Zeile 20) ------------------------------------------------------------------- inputfi...s?v=13c (Zeile 20) Field "Inputfield_fieldset1" detected a change to a dependency field! Beginning dependency checks... inputfi...s?v=13c (Zeile 20) ---- inputfi...s?v=13c (Zeile 20) Start Dependency 0 inputfi...s?v=13c (Zeile 20) Condition type: show inputfi...s?v=13c (Zeile 20) Field: socialnetworkactivation inputfi...s?v=13c (Zeile 20) Operator: = inputfi...s?v=13c (Zeile 20) Required value: 0 inputfi...s?v=13c (Zeile 20) Field socialnetworkactivation - Current value: 1 inputfi...s?v=13c (Zeile 20) Field socialnetworkactivation - Matched? NO inputfi...s?v=13c (Zeile 20) Field socialnetworkactivation - Current value: 0 inputfi...s?v=13c (Zeile 20) Field socialnetworkactivation - Matched? YES inputfi...s?v=13c (Zeile 20) ---- inputfi...s?v=13c (Zeile 20) Determined that field "Inputfield_fieldset1" should be visible. inputfi...s?v=13c (Zeile 20) Field is now visible. inputfi...s?v=13c (Zeile 20) 1 visibility changes were made. 1 Link to comment Share on other sites More sharing options...
LostKobrakai Posted April 3, 2015 Share Posted April 3, 2015 So the logic seems to be working. Could you please inspect one of those two fields? The wrapping li.Inputfield of the field should have "display:none" and "display:block" as inline style and switch between them as you change the checkbox. Link to comment Share on other sites More sharing options...
Juergen Posted April 3, 2015 Author Share Posted April 3, 2015 Here is the problem: Field snintegration - Current value: 1 inputfi...s?v=13c (Zeile 20) Field snintegration - Matched? YES inputfi...s?v=13c (Zeile 20) Field snintegration - Current value: 0 inputfi...s?v=13c (Zeile 20) Field snintegration - Matched? NO inputfi...s?v=13c (Zeile 20) ---- inputfi...s?v=13c (Zeile 20) Determined that field "facebookaktivation" should be visible. inputfi...s?v=13c (Zeile 20) Field is already visible. The field is always visible independent if the value matches or not!!!!!! This only happens if I choose the value "1" as condition - with the value "0" it works as expected. 1 Link to comment Share on other sites More sharing options...
Juergen Posted April 3, 2015 Author Share Posted April 3, 2015 With condition "0" and checkbox checked: <li style="display: block;" class="Inputfield InputfieldCheckbox Inputfield_facebookaktivation..... With condition "0" and checkbox unchecked: <li style="display: none;" class="Inputfield InputfieldCheckbox Inputfield_facebookaktivation.... Work as expected!! With condition "1" and checkbox checked: <li class="Inputfield InputfieldCheckbox Inputfield_facebookaktivation.... With condition "1" and checkbox unchecked: <li class="Inputfield InputfieldCheckbox Inputfield_facebookaktivation.... As you can see no CSS-inline-style will be added!! Link to comment Share on other sites More sharing options...
LostKobrakai Posted April 3, 2015 Share Posted April 3, 2015 Please do first look at the Edit part. I seems like the script adds the alternative "0" as value for unchecked checkboxes to the checked ones as well. Could you please add the consoleLog statement in the inputfields.js: if(($field.attr('type') == 'checkbox' || $field.attr('type') == 'radio') && !$field.is(":checked")) { // @todo this part will no longer work with multi-checkbox/radio fields consoleLog("*** Added 0 as alternative ***"); values[1] = '0'; } If this prints the line for both unchecked and checked states than we at least know where it's not working correctly. Edit: Looking at your logs again, maybe this isn't the issue, but more likely the checkbox returning a value of 1 even if it's unchecked. Could you also please test if this lines are correctly setting value to null. // value of the dependency field we are checking (if not already populated above) if (value === null) { if($field.attr('type') == 'checkbox') { value = $field.is(":checked") ? $field.val() : null; } else { value = $field.val(); } } 3 Link to comment Share on other sites More sharing options...
Juergen Posted April 3, 2015 Author Share Posted April 3, 2015 if(($field.attr('type') == 'checkbox' || $field.attr('type') == 'radio') && !$field.is(":checked")) { // @todo this part will no longer work with multi-checkbox/radio fields consoleLog("*** Added 0 as alternative ***"); values[1] = '0'; } This code doesnt add anything to the log files (wheter checked or unchecked). // value of the dependency field we are checking (if not already populated above) if (value === null) { if($field.attr('type') == 'checkbox') { value = $field.is(":checked") ? $field.val() : null; } else { value = $field.val(); } } This piece of code solves my problem. Now checkbox fields work as expected as dependency field! Thank you so much for your effort!!!!! From now on you are no longer LostKobrakai - you are BestKobrakai Best regards Jürgen 1 Link to comment Share on other sites More sharing options...
LostKobrakai Posted April 3, 2015 Share Posted April 3, 2015 The second part is just copied from the current inputfields.js file. Sure you run the latest dev? Link to comment Share on other sites More sharing options...
Juergen Posted April 3, 2015 Author Share Posted April 3, 2015 Yep I think so! ProcessWire Core (Development) ProcessWire dev 2.5.24 2.5.24 Auf dem neuesten Stand But your piece of code was not in my JS file. Link to comment Share on other sites More sharing options...
Juergen Posted April 3, 2015 Author Share Posted April 3, 2015 If I change $config->debug = true to $config->debug = false in config.php the strange behaviour is back. If I change it back then it works. I will add it to the minified version too because it will be loaded if debug is off. Addition: I have downloaded the latest min-version from Github and now it works also with debug off. I have updated my PW to the latest version but I had another js version - very strange!!!! Now everything works fine. Link to comment Share on other sites More sharing options...
Juergen Posted April 4, 2015 Author Share Posted April 4, 2015 For all users with the same problem: Downloading inputfields.js and the minified version from Github solved the problem. I had slightly different js files in my directory and they have caused the strange behaviour. Thanks to all contributors for their efforts to solve the problem. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now