How do I set checkboxes as checked in a dynamically loaded group? I've spent all day looking here, and in the code trying to work it out.
It might be made harder by the lack of a direct selection that contains the required data (explanation below), but I can't find anything (up-to-date) here about it, and looking at the code doesn't show me a way of doing it.
I'm creating a form that people can use to set up their own contact data.
The checkboxes are for tags that can be attached to the contact details.
I'm trying to do the work in custom code launched in the "On Load" event, but I'm not getting any boxes checked.
I select the list of tags available for contacts to create the checkbox group.
I then select the tags that the current user already has attached to the contact details and need to use this to set the relevant checkboxes checked.
TIA
Mark
It might be made harder by the lack of a direct selection that contains the required data (explanation below), but I can't find anything (up-to-date) here about it, and looking at the code doesn't show me a way of doing it.
I'm creating a form that people can use to set up their own contact data.
The checkboxes are for tags that can be attached to the contact details.
I'm trying to do the work in custom code launched in the "On Load" event, but I'm not getting any boxes checked.
I select the list of tags available for contacts to create the checkbox group.
I then select the tags that the current user already has attached to the contact details and need to use this to set the relevant checkboxes checked.
TIA
Mark
Hi Mark,
Please add a Debugger to the On Load event of your form and copy and paste the output here.
ChronoForms doesn't do a good job of re-loading either dynamic elements or check box groups :-( It is possible though using custom code. If I can see what your inputs are called and how they are being loaded I'll see if I can work out an example.
Just to check - when you say the that the tag checkboxes are dynamically loaded is this because you are getting the checkbox options from a DB Read action?
Bob
Please add a Debugger to the On Load event of your form and copy and paste the output here.
ChronoForms doesn't do a good job of re-loading either dynamic elements or check box groups :-( It is possible though using custom code. If I can see what your inputs are called and how they are being loaded I'll see if I can work out an example.
Just to check - when you say the that the tag checkboxes are dynamically loaded is this because you are getting the checkbox options from a DB Read action?
Bob
Thanks for your reply Bob,
I only use a DB Read to get the contact data, that all seems to be working so I won't clutter this thread up with it.
I'm generating the data for the checkboxes in the custom code section, calling a helper. These together produce an array that is used to drive the group. I've attached a snap of the control dialogue for it.
Just to show you two examples (of 22) from the debugger output of the array that's driving the checkboxes (again for de-cluttering reasons) here's one checkbox that shouldn't be checked and one that should. I've added the "checked" array item in the custom code, but haven't found a way to make it work that way. I tried to use the "values" item on the group control dialogue, but not only will that not take the value of a variable, it actually won't work for numeric values at all I think😟
I only use a DB Read to get the contact data, that all seems to be working so I won't clutter this thread up with it.
I'm generating the data for the checkboxes in the custom code section, calling a helper. These together produce an array that is used to drive the group. I've attached a snap of the control dialogue for it.
Just to show you two examples (of 22) from the debugger output of the array that's driving the checkboxes (again for de-cluttering reasons) here's one checkbox that shouldn't be checked and one that should. I've added the "checked" array item in the custom code, but haven't found a way to make it work that way. I tried to use the "values" item on the group control dialogue, but not only will that not take the value of a variable, it actually won't work for numeric values at all I think😟
[Tags] => Array
(
[0] => Array
(
[id] => 19
[title] => Artists
[value] => 0
)
(1-4 not shown here)
[5] => Array
(
[id] => 5
[title] => Therapist/Healer
[value] => 0
[checked] => checked
)
)
It would be nice if there was a "built in" solution, tho' looking at the code I don't see that there could be at the moment.
Here's a javascript solution.
Get the list of checkbox values to be marked as checked and put them somewhere on the form, a hidden input field is what I've done.
Then include the following javascript
This just runs when the form is ready.
The id "theseTags" denotes the field holding the values I want checked.
I've given the class "ProTags" to the checkboxes (as you can [almost] see in the control dialogue above).
The right boxes are checked when the form is displayed.
Of course, now I need a way to write them back to the database when the form is saved...
Here's a javascript solution.
Get the list of checkbox values to be marked as checked and put them somewhere on the form, a hidden input field is what I've done.
Then include the following javascript
jQuery(document).ready( function($) {
// make an array of the list of tags to be checked
var cTs = jQuery('#theseTags').attr('value');
var cChecked = cTs.split(',');
for(i=0; i < cChecked.length; i++ ) {
jQuery(".ProTags[value='" + cChecked[i] + "']").attr('checked', true);
}
});
This just runs when the form is ready.
The id "theseTags" denotes the field holding the values I want checked.
I've given the class "ProTags" to the checkboxes (as you can [almost] see in the control dialogue above).
The right boxes are checked when the form is displayed.
Of course, now I need a way to write them back to the database when the form is saved...
This topic is locked and no more replies can be posted.