bolt: [bug] rare jquery serialization error, when saving record
repro
- create field called
elements:in any contenttype. In my case it’s a selectbox input. - goto edit content and try to save from editcontent page
- ajax post is not working
reason
We are serializing form data by jquery’s native serialize
https://github.com/bolt/bolt/blob/3.4/app/src/js/modules/editcontent.js#L381 :
It calls serializeArray, and that one calls this.prop('elements').
Which unfortunately, relies on to getting formDomNode.elements - a special DOM-node property for getting all child inputs. Which is overwritten by browser behaviour.
It’s a known bug of jquery. See below.
So let’s find out.
repro2
- create field called
elements:in any contenttype. In my case it’s a selectbox input. - goto edit content
- run in console
$f = $('form[name="content_edit"]').$frepresents a form. - run
$f.serialize(). It returns"".
Why? Because Jquery uses .props(‘elements’) here:
//...
serializeArray: function() {
return this.map( function() {
// Can add propHook for "elements" to filter or add form elements
var elements = jQuery.prop( this, "elements" );
return elements ? jQuery.makeArray( elements ) : this;
} )
//...
here’s the bug report: https://bugs.jquery.com/ticket/13651
5. run $f.prop('elements'). It returns (prints in console) our <select ..> element. And it’s expected, that it will return the list of all inputs in form.
6. Now remove our select element $f.prop('elements').remove(). And try $f.prop('elements') again. Works like a charm.
Possible solution
I know, that it’s a jquery/DOM problem. But maybe we can add some prefixes, or name modifiers to inputs — and then remove them after serialization. To be sure that we will not overwrite any node’s original property.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 15 (11 by maintainers)
I was merely pointing out that the issue @Boorj was bringing up (“Reserved terms in SQL and/or jquery”) is no longer an issue in Bolt 4, so far.