Programmatic checkbox entries

There was an interesting example given here (thanks @marcus-j-davies), showing how to create varying numbers of checkbox items when configuring a node. That thread is closed, therefore this new question.

I'd like to do something like the example that but the problem is that it requires the number of checkbox items to be known beforehand (3 in the example). However in my use case the number of items is not known beforehand and will be discovered at runtime. I can obtain the number of items and associated item data at oneditprepare in the javascript section but (based on that information) could anyone outline how to then dynamically generate the correct number of form-row entries in the html section?

That is to ask - if I find at run time that I need 4 checkbox items, how to generate 4 form-row divs; if I find I need 7 checkbox items, how to generate 7 form-row divs etc. ?

Thanks for any help,

The trick is probably to understand that you have access to jQuery which makes making dynamic UI elements fairly easy. So you can just loop through whatever is defining the number of checkboxes and use jQuery to create the inputs.

Thanks for the pointer.

I repurposed a code example in this thread and it works just fine (thanks @Steve-Mcl). I have some formatting details to sort out now but that's a different problem.

Thanks again,

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.