I'm working on the User role permissions and for that I've created a form like this:
The generated HTML for each checkbox is
<div class="checker" id="uniform-department_create">
<span>
<input type="checkbox"
class="form-control department"
id="department_create"
name="department_create"
value="create">
</span>
</div>
now onSubmit I'll be calling a function that would pull the user's permissions. It looks like this:
var designationForm = {
// All permissions must be added to this Array
// to manipulate checkboxes
permissions: Array('department','customer','designation'),
...
get_permissions: function() {
var allowed = Array();
$.each(designationForm.permissions, function(index, permission) {
allowed[permission] = Array();
$.each($("."+permission),function(input, value) {
if ($("#uniform-"+$(value).attr('id') + " span").hasClass('checked')) {
allowed[permission] += "{"+$(value).attr('value')+":"+"true},";
} else {
allowed[permission] += "{"+$(value).attr('value')+":"+"false},";
}
});
return allowed[permission];
});
// console.log(allowed);
return allowed;
},
...
}
what it does is basically check permissions array and iterate through all permissions if it finds a checkbox's span containing the class "Checked" it adds it to the allowed array.
if I console the result then I can see correct return but I'm unable to return the resultant array.
get_permissionsfunction