On Nov 15, 2012, at 12:26 PM, Albert Català wrote:
> Jordon Bedwell wrote in post #1084597:
>> On Thu, Nov 15, 2012 at 10:23 AM, Albert Catal <[email protected]>
>> wrote:
>>> Easy and clean, thanks you
>>
>> If you want/need to prevent "enter" from submitting a form, you are
>> doing it wrong and you could be be alienating some disabled people who
>> do not use a mouse and rely on their keyboard. I know even if that's
>> not the case, if I ran into a site that prevented me from pressing
>> enter to submit a form (because I am still a tab, tab, enter person) I
>> would walk away from that site and probably blacklist it in my
>> personal DNS.
>
> Hello, My problem is than I'm doing a excel style form, and some fields
> have remote calls (onchange) to calculate another fields. And the form
> has a submit button, so I user press enter the remote call (ajax call)
> is not finished (some times not initiated) when the form is submited and
> saved with bad calculated values.
> To solve it, I have to do two things:
> 1 - Prevent enter key (this forum issue)
> 2 - And,despite this, user can click on submit button faster than field
> onchange function is finished. This second issue i still don't know how
> to solve it
>
> What do you tink?
> Do you hace the pont 2 answer?
>
> thanks a lot and sorry for my bad english
Your English is guaranteed 100% better than my attempt at your native language,
unless that's Latin (didn't think it was).
What you need to do is use callback functions in your processing JavaScript to
disable the submit button while they're running, and enable them when they're
done. That way if you have blocked the enter key, the only way the form will be
submitted is with a click on an enabled form button. Here's a quick mockup (I
don't know what your existing cell calculation code looks like).
//stop all submits from the form
$$('form').invoke('observe', 'submit', function(evt){
evt.stop();
});
//let a click on <input type="submit" id="real_submit" /> send the form
$('real_submit').observe('click', function(evt){
this.form.submit();
});
//fake spreadsheet code for demo purposes
$$('input[type="text"]').invoke('observe', 'blur', function(evt){
var elm = evt.element();
var submits = elm.select('input[type="submit"]');
new Ajax.Request('/some/endpoint', {
parameters: {id: elm.id, value: $F(elm)},
onCreate: function(){ submits.invoke('disable'); }, //can't be
clicked
onSuccess: function(transport){
submits.invoke('enable'); //can be clicked
$('total').update(transport.responseText);
}
});
});
That's all written with Prototype.js methods, but you could do similar in any
JavaScript you like.
Walter
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit https://groups.google.com/groups/opt_out.