EasyUI Forum
October 10, 2024, 10:14:05 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Bug in form load (checkbox)  (Read 26610 times)
anton.dutov
Newbie
*
Posts: 27


View Profile
« 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
Logged
Kevin
Jr. Member
**
Posts: 52


View Profile Email
« Reply #1 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.
Logged
anton.dutov
Newbie
*
Posts: 27


View Profile
« Reply #2 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.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!