Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery is unable to set the prettyCheckable plugin radio button programmatically

I am using the prettyCheckable jquery plugin to make my checkboxes and radio buttons look pretty and if I use jquery to set the property checked it does not work because the plugin hides the actual checkbox and makes it's own override HTML to pretty up the checkbox/radio, therefore the jquery doesn't recognize when I check the radio or checkbox

//on button click I tried all the things, but nothing is working. 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));
like image 529
user2674021 Avatar asked Aug 25 '13 07:08

user2674021


People also ask

How to make radio button checked Using jQuery?

We can check the status of a radio button by using the :checked jQuery selector together with the jQuery function is . For example: $('#el').is(':checked') . It is exactly the same method we use to check when a checkbox is checked using jQuery.

What is iCheck js?

iCheck is a fancy and lightweight jQuery plugin that allows you to create touch-enabled, fully accessible, highly customizable checkboxes and radio buttons with 25 built-in options and 6 skins.

How do you set up a radio check?

To set a radio button to checked/unchecked, select the element and set its checked property to true or false , e.g. myRadio. checked = true . When set to true , the radio button becomes checked and all other radio buttons with the same name attribute become unchecked. Here is the HTML for the examples in this article.


1 Answers

Not sure how much of a hack this is but I was able to get a div to check and uncheck a prettyCheckable checkbox. I noticed when I removing the class="checked" from the that prettyCheckable includes the checkbox became 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 the (which is .next() to the prettyCheckable element) and setting checked=true in the original checkbox element are both needed for it to work. Yet my if cookie is set piece is able to check the box with only the 's class. Like I said I don't know how bad of a hack this is but it worked for me hopefully it helps you out. Not sure why prettyCheckable doesn't have this ability or atleast document it because I could not find anything.

like image 138
Micah Avatar answered Oct 07 '22 13:10

Micah