I'm working with Spring webflow and I have a form: switchbox checkbox element in my jsp that by default must be disabled. I'm going crazy trying to enable it using JQuery when a condition is met.
<form:checkbox id="anId" path="" value="" cssClass="js-switch" disabled="true"/>
The html code it generates is like this:
<input id="anId" class="js-switch" disabled="" type="checkbox" value="" data-switchery="true" style="display: none;">
<span class="switchery" id="anId" style="">
<small style=""></small>
</span>
I have tried changing the disabled to true, removing the disabled attribute, too:
$("#anId").trigger("chosen:updated");
How should I implement this to make it work?
I frame your correct answer because with the information I gave, it is. The problem lies in:
<span style="patatan:a_lot_of_stuff;" class="switchery" id="anId" />
I did not copy for brevity, it is who gives the appearance of disabled to it. Knowing that, it's just:
$("span#anId").attr("style", "pataton:otra_castaña;");
and
<small style="etc" />
well more of the same:
$("span#anId small").attr("style", "stuff");
With this the click event does not work or forcefully, I tried:
$("span#anId").off("click");
... at the beginning (I do not know why) but then I used it when I want it to be disabled again and behave as such. What I did:
$("div#el_que_lo_contiene").click(function(){
if($("span#anId small").css("left")=="20px"){
$("span#anId small").attr("style", "left:0px;y:mas;");
$("input#anId").val(false);
} else {
$("span#anId small").attr("style", "left:20px;y:mas;");
$("input#anId").val(true);
}
});
To send the value that contains the input (which is who actually stores it) I do something like this:
$("send").click(function(){
$("input#anId").removeAttr("disabled");
});
and should reach the controller ... Then control the behavior and ready.