we're talking about something that goes on only on click. I feel more 
"safe" knowing that if some weird things are going on with either the name 
or the value, it'll be handled by jquery "serialize()", as any other field. 
Performance-wise, it's something that happens client-side, so no worries. 
Also, it's only binding to the "submitting" elements in the form context, 
which is probably the best way to do it without performance penalties from 
event bubbling.
@leonel, @anthony: do you spot any issues with this implementation ? 

On Saturday, November 8, 2014 1:42:52 AM UTC+1, DenesL wrote:
>
> LOL
> That seems to work too.
> Would it be more efficient to add the hidden field than appending to the 
> serialized string with the 2 calls to encodeURIComponent ?.
>
> In any case I will get the info I need.
>
> Thanks Niphlod.
>
>
>
> On Friday, November 7, 2014 6:26:50 PM UTC-5, Niphlod wrote:
>>
>> grrr... except of course the console.log line ^_^'
>> Time to go to sleep...
>>
>> On Saturday, November 8, 2014 12:24:35 AM UTC+1, Niphlod wrote:
>>>
>>> ah shoot, submit can also be triggered pressing "enter"...
>>> guess we're stuck with this then...... opinions ? (if everybody agrees 
>>> I'll send a PR)
>>>
>>> trap_form: function (action, target) {
>>>       /* traps any LOADed form */
>>>       $('#' + target + ' form').each(function (i) {
>>>         var form = $(this);
>>>         form.attr('data-w2p_target', target);
>>>         if(!form.hasClass('no_trap')) {
>>>           form.submit(function (e) {
>>>             console.log(form.serialize())
>>>             web2py.disableElement(form.find(web2py.
>>> formInputClickSelector));
>>>             web2py.hide_flash();
>>>             web2py.ajax_page('post', action, form.serialize(), target, 
>>> form);
>>>             e.preventDefault();
>>>           });
>>>           /* simulating behaviour of non-ajax forms, where the click on 
>>> a submit
>>>           button also submits its name and value */
>>>           form.on('click', web2py.formInputClickSelector, function (e) {
>>>             e.preventDefault();
>>>             var input_name = $(this).attr('name');
>>>             if (input_name != undefined) {
>>>               $('<input type="hidden" />').attr('name', input_name)
>>>               .attr('value', $(this).val()).appendTo(form)
>>>             }
>>>             form.trigger('submit');
>>>           })
>>>         }
>>>       });
>>>     },
>>>
>>>

-- 
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.

Reply via email to