marioizquierdo / jquery.serializeJSON

Serialize an HTML Form to a JavaScript Object, supporting nested attributes and arrays.
MIT License
1.72k stars 431 forks source link

Disabled elements are ignored? #99

Closed SheldonSir closed 5 years ago

SheldonSir commented 5 years ago
<div>
        <div><span>RendingFrames</span></div>
         <input id="name" type="text" name="Info[Frames]" value="0"  disabled/>
</div>

After I set the input style to disabled, the result of jQuery.serializeJSON() will be an empty json object. Of course this is the result I want.

<div disabled>
        <div><span>RendingFrames</span></div>
         <input id="name" type="text" name="Info[Frames]" value="0" />
</div>

If I set the style of the div to disabled, due to the inheritance relationship, its child element input style should also be disabled, but the result obtained by jquery.serializeJSON() is

"Info":{
    "Frames":"xxxx"
}
SheldonSir commented 5 years ago

Ok, this is my fault.

The jquery.serializeArray() method uses the standard W3C rules for successful controls to determine which elements it should include; in particular the element cannot be disabled and must contain a name attribute.

Disabled controls

marioizquierdo commented 5 years ago

You got it. The disabled property is not assumed to be inherited from parent elements. The input needs to have its own disabled property.