Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Must click submit button twice for submitting form #2

Closed
drq opened this issue Oct 8, 2012 · 11 comments
Closed

Must click submit button twice for submitting form #2

drq opened this issue Oct 8, 2012 · 11 comments
Assignees

Comments

@drq
Copy link
Contributor

drq commented Oct 8, 2012

Hi
I m using Alcapa2 for checking the power of the framework…
I saw that in a form there is this problem:

when I change a invalid text in a valid text and sudden I click on the submit button I must click 2 times for sending the form to the server (not just once )!!

It is possible to correct this problem ?

@drq
Copy link
Contributor Author

drq commented Oct 8, 2012

Hey,

How did you implement the submit button?

Did you add your own submit handler?

Yong

@publicocean0
Copy link

<script type="text/javascript"> $(function() { Alpaca.setDefaultLocale("it_IT"); $("div[id='form_1']").alpaca({ "schema": { "type":"object", "properties": { "username": { "type":"string", "title":"Username", "required":true, "pattern":"^[a-zA-Z0-9_]+$" }, "password": { "type":"string", "title":"Password", "required":true, "pattern":"^[a-zA-Z0-9_]+$" } } }, "options":{ "renderForm":true, "form":{ "attributes":{ "action":"@_CURRENT_URI", "method":"post" }, "buttons":{ "submit":{} } }, "fields": { "username": { "size": 20, "helper": "Please enter your username" }, "password": { "size": 20, "helper": "Please enter your password" } } }, "data": { "username": "{$username}", "password": "{$password}" }, "view" :{ "fields": { "/username": { "messages": { "invalidPattern": "Invalid Age (Must be a number) !" } } } }, "postRender": function (renderedField) { var form = renderedField.form; if (form) { form.registerSubmitHandler(function(e) { return (renderedField.isValid(true)) ; }); } } }); }); </script>

@publicocean0
Copy link

i saw also in your examples in the website there is the same problem ....
the first click call the validation , the second one the submission ...

but if you click in the submit button i should validate and submit on the fly ...

@drq
Copy link
Contributor Author

drq commented Oct 9, 2012

The root cause of the issue is that when Alpaca did the validation and found out the field was valid, it removed the error message as well as the red box around the field. This made the whole field shift upwards. The validation is triggered on the blur event which is fired before the click event.

That is why it wouldn't consider the click was on the submit button since the button was moved upwards. If the submit doesn't get the click event, the custom submit handler will never get invoked.

Actually if you click on the top edge of the submit button, you may just need one click.

There are a few ways to fix it. One easy way is to make the button bar at the fix location. Or we can add delay to the blur handler. But none of them is a solid solution.

I will do more research and find a better fix.

@ghost ghost assigned drq Oct 10, 2012
@publicocean0
Copy link

Maybe the reason is that the click event is async and so it can occur before then the validation event related with another event (on focus maybe???). I think you might force to call validation subroutine also in on submit .... You can add a variable for keeking the information of the last valitation for not calculate twice the validation.

@publicocean0
Copy link

Else maybe there is also this mor elegant solution : http://stackoverflow.com/questions/7721689/how-to-set-the-order-or-priority-of-functions-call-in-jquery-or-javascript ... but i never used it. :) i hope to have been useful

@publicocean0
Copy link

@drq
Copy link
Contributor Author

drq commented Oct 11, 2012

@publicocean0
Copy link

Ok thanks this could be a work around.
Anyway i advice in the future to refactor the framework for handling directly this problem: by using 2 click instead 1 could create strange situation in complex form where a developer use custom logic.

@drq
Copy link
Contributor Author

drq commented Oct 15, 2012

I just checked in the patch to the framework so that you won't need to add custom code in the callback.

http://www.alpacajs.org/examples/forms/login/localized-login-form.html

The patch is in Form.js

            $(v).mousedown(function() {
                var _this = $(this);
                _this.attr("button-pushed","true");
                setTimeout(function() {
                    if (_this.attr("button-pushed") && _this.attr("button-pushed") == "true" ) {
                        _this.click();
                    }
                }, 150);
            });
            $(v).click(function() {
                $(this).removeAttr("button-pushed");
            });

@drq drq closed this as completed Oct 15, 2012
uzquiano added a commit that referenced this issue Feb 19, 2013
Two mechanisms - auto-submit enable/disable + custom submit validation handling
Two additional example forms (Simple #1 and Simple #2)
uzquiano added a commit that referenced this issue Jun 23, 2015
…dress item #19 on feature list

Bower components updated for moment.js and eonasdan-bootstrap-datetimepicker
@abdessamadely
Copy link

After some trial and error, I found that I was using only oninvalid on some inputs and oninput event on others.

I don't know the actual issue, but I made it work by adding both oninvalid and oninput events, on each input.

Example:

fullname.addEventListener("invalid", function() { if (fullname.validity.valueMissing) { fullname.setCustomValidity("custom required msg"); } else { fullname.setCustomValidity(""); } });

fullname.addEventListener("input", function() { fullname.setCustomValidity(""); });
I wish it does help someone

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants