I’ve seen many different variations of my question, but nothing specific to my use case. I am trying to create a form field with multiple checkboxes and have done so successfully. If I do something like…
$("#select_all_1").click(function() {
count1++;
count1 % 2 ? $firstFunction1() : $secondFunction1();
});
function $firstFunction1 () {$('#is_access_manager_department_choices input[type=checkbox]').prop('checked', true);}
function $secondFunction1 () {$('#is_access_manager_department_choices input[type=checkbox]').prop('checked', false);}
This totally works and does what I want it to.
What I’m trying to do is a variation of this. I want to get a list of users, potentially as a hidden input and then when the user clicks on select user group, it will only selectively select ( add a checkmark) to those users that are on my hidden list….I don’t want to select all users…only the "hidden" ones.
I’ve seen array examples…but only for select all…I’ve found something like this…dynamic check/uncheck of checkboxes but again it does all. I’m thinking I need to create a hidden input with all of the checkboxes checked and then loop through and do a compare of my user list to the whole user list and then if it exists on my user list…check it…But just can’t seem to figure out how to piece it together.
Thanks in advance for any thoughts.
2
Answers
I ultimately pulled together a solution based on various solutions that I found. I ultimately used AJAX so that when a user clicks on the dropdown field, a URL is executed to populate the field in question.
AJAX
MY HTML..
My View( Class Based )
If I understand you correct and it is OK to submit the data using JavaScript this could be a solution. Instead of adding input elements/checkboxs to the form you can add data about the users when the form is submitted.
By getting the form data in a FormData object you can then add more data to the object and send that in the end.