EasyUI Forum

General Category => Bug Report => Topic started by: anton.dutov on March 31, 2012, 05:59:42 PM



Title: Bug in form load (checkbox)
Post by: anton.dutov on March 31, 2012, 05:59:42 PM
For exmple we have following form
Code:
<form id="ff" method="post">
  <input type="checkbox" name="is_active" value="true" />
</form>

And code
Code:
$('#ff').form('load',{
  is_active:true
});

This code will set checkbox state to checked but nothing happens, and when we change code to

Code:
$('#ff').form('load',{
  is_active:'true'
});
it works fine

Then i looked at jquery.form.js

there is code for checkbox and radio
Code:
var rr = $("input[name=\""+_17+"\"][type=radio], input[name=\""+_17+"\"][type=checkbox]",_18);
$.fn.prop ? rr.prop("checked",false) : rr.attr("checked",false);
rr.each(function(){
  var f=$(this);
  if(f.val()==val){
    $.fn.prop ? f.prop("checked",true) : f.attr("checked",true);
  }
});

when we have is_active:true
in line

Code:
  if(f.val()==val){
comparsion string==bool witch returns false anytimes for boolean values

There we need change it to
Code:
if(f.val()==String(val)){
to valid value comparsion


Title: Re: Bug in form load (checkbox)
Post by: Kevin on April 04, 2012, 08:54:32 PM
Hi Anton

I don't think this is a bug. You have defined your value as a string (value="true"). In the same way you could define this as value="1". Thus to set the check box, you would have;
   $('#ff').form('load',{
      is_active:'1'
   });

Technically there is no boolean type true in HTML, which might be confusing you.


Title: Re: Bug in form load (checkbox)
Post by: anton.dutov on April 12, 2012, 06:25:07 AM
Hi Kevin,

But usually chekcbox represent bool values and form loads values from json-notation direcly, i think no problems there to change behavior in this case.