Hi all,
a bit of background on this RFC:
Any form inside a component that has ajax=True, i.e. a form inside a
LOAD(..., ajax=True) component,
will be trapped and only the fields are serialized.
According to jQuery's serialize: "No submit button value is serialized
since the form was not submitted using a button."
which is not always true, quite the opposite in web2py forms, most times
they will be submitted using a button.
Apart from that, I came across the need to use components with several
submit buttons that should be processed differently depending on the button
pressed. So I needed the serialization to include that information.
To that effect I modified the trap_form function inside web2py.js as
follows:
changed
form.submit(function (e) {
web2py.disableElement(form.find(web2py.formInputClickSelector));
web2py.hide_flash();
web2py.ajax_page('post', url, form.serialize() + srlbtn, target,
form);
e.preventDefault();
});
to
var srlbtn;
form.click(function (e){
/* serialize button used to submit form (only if type is submit)*/
var btn = e.target;
srlbtn = btn.type=="submit" ? ('&' + (btn.name ? btn.name :
btn.type) + '=' + btn.value) : "";
});
form.submit(function (e) {
web2py.disableElement(form.find(web2py.formInputClickSelector));
web2py.hide_flash();
web2py.ajax_page('post', url, form.serialize() + srlbtn, target,
form);
e.preventDefault();
});
Note that the button is serialized as button.name=button.value but only if
button.type is 'submit'.
It seems to work with IE & Firefox.
Comments?,
Denes
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.