JQuery cannot install prettyCheckable plugin softkey

I use the prettyCheckable jquery plugin to make my checkboxes and radio buttons convenient, and if I use jquery to set the property, it does not work because the plugin hides the actual flag and makes it its own html override for checkbox / radio, so jquery does not recognize when I check the radio or checkbox

// by pressing a button I tried everything. but worthless work. please, help

<input type="radio" id="rdTypeAdd" name="taxationtype" class="radiobutton" value="+" data- label="Additive" data-customclass="margin-right" checked="checked" /> <input type="radio" id="rdTypeSub" name="taxationtype" class="radiobutton" value="-" data-label="Subtractive" data-customclass="margin-right" /> $('#rdTypeAdd').buttonset(); $('[name="rdTypeAdd"][value="+"]').prop("checked", true); $('#rdTypeAdd').buttonset("refresh"); //$('[name="rdTypeAdd"][value="+"]').attr("checked", true); //$('[name="rdTypeAdd"][value="+"]').prop("checked", true).trigger("change"); //($('.rdTypeAdd').prop('checked',true)); 
+4
source share
5 answers

Not sure how many of this hacked, but I was able to get a div to check and uncheck prettyCheckable. I noticed that when class = "checked" was removed from this prettyCheckable parameter, the checkbox is unchecked.

 $("#checkbox").prettyCheckable(); $("#checkboxDiv").click(function() { if ($("#checkbox").is(':checked')) { $("#checkbox").next().removeClass("checked"); $('#checkbox').each(function(){ this.checked = false; }); } else { $("#checkbox").next().addClass("checked"); $('#checkbox').each(function(){ this.checked = true; }); } }); 

Adding or removing the "checked" class from (which is .next () to the prettyCheckable element) and setting check = true in the original flag element is necessary for it to work. However, my cookie, which can be set, can only validate a field with a class. Like I said, I don’t know how bad this is, but it worked for me, I hope this helps you. Not sure why prettyCheckable doesn't have this ability or at least document it because I didn't find anything.

+3
source

You can use some pretty proven features:

$('[name="rdTypeAdd"][value="+"]').prettyCheckable('check');

and

$('[name="rdTypeAdd"][value="+"]').prettyCheckable('uncheck');

+2
source

This answer builds on @ kravits88 and the github problem

 var $radio = $('[name="rdTypeAdd"][value="+"]'); $radio.prettyCheckable('check'); $radio.prop('checked', true).change(); $radio.click(); 
+1
source

It seems to work for me. Essentially, you need to find the parent tag that prettyCheckable created around your checkbox, and set it the same way as the input:

 $("#element").prop("checked", true).parent().find("a:first").addClass("checked"); 
0
source

Setting the checked attribute to something should work, as shown here .

 $('#rdTypeAdd').attr("checked","checked"); 
-one
source

Source: https://habr.com/ru/post/1498801/


All Articles