Open ragulka opened 10 years ago
I'm a bit of two minds about this.
On one hand, I see that it is convenient for you if jquery-simulate-ext simulates the native browser behavior.
On the other hand, there is a lot of other native browser behavior which jquery-simulate-ext does not cover. Especially with your other feature request (#11), where I added key combos for Esc, ↑ and ↓, there is more native behavior which isn't covered (blur, scroll up and down, increase/decrease input
elements with type number
, etc.).
So the question is whether there is a general way to simulate native behavior without having to implement it all in jquery-simulate-ext?
One thing that came into my mind is: what is the advantage of
$ele.simulate('key-sequence', {sequence: 'foo{enter}'});
over
$ele.simulate('key-sequence', {sequence: 'foo'});
$ele.trigger('submit');
I mean, are there any situations where it is not possible or very complicated to use .trigger()
to trigger the default behavior?
For asynchronous simulation (i.e. delay
> 0), one could do it like that:
$ele.simulate('key-sequence', {sequence: 'foo', delay: 5, callback: function() {
$ele.trigger('submit');
});
My particular use case is that I need to test whether a specific option blocks submitting the from when pressing enter or not. There are cases when pressing enter should submit the form and some cases when it should not.
Simply triggering submit
on the form would not work for that case.
Interesting. How is the submission prevented when enter is pressed? Do you check a condition on the submit event or on a keyup/keydown event and then cancel the event? Or is it native browser behavior (e.g. HTML5 input validation like email or URL fields)?
In my case, I am simply returning false in a keyup event handler based on some criteria.
2013/12/30 Jochen Ulrich notifications@github.com
Interesting. How is the submission prevented when enter is pressed? Do you check a condition on the submit event or on a keyup/keydown event and then cancel the event? Or is it native browser behavior (e.g. HTML5 input validation like email or URL fields)?
— Reply to this email directly or view it on GitHubhttps://github.com/j-ulrich/jquery-simulate-ext/issues/13#issuecomment-31328006 .
I was trying to use key-sequence to enter user input on a field and then pressing enter to submit the form. Currently it seems that no submit event is triggered though.
To be more precise: it shouldn't simply trigger the submit event, but actually try to submit the form.