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

Validation preSubmit and isValid method #31

Closed
andtankian opened this issue Nov 28, 2018 · 4 comments
Closed

Validation preSubmit and isValid method #31

andtankian opened this issue Nov 28, 2018 · 4 comments

Comments

@andtankian
Copy link

What's up guys?

I couldn't found neither in docs or source code a way to verify if the form is valid.

In fact, I need to do extra things before properly submit the form (like sanitize inputs, made some animations, etc.)

Today, is it possible? Am I missing some method here?

If not, I suggest to implement these methods. It would be very interesting to have these.

Thank you very much.

@Mevrael
Copy link
Owner

Mevrael commented Nov 28, 2018

Hi @andtankian

I believe you are well.

The first docs for BunnyJS are Web Standards.

You can check if form is valid with native form.checkValidity() and you can listen for submit event and add event.preventDefault() to cancel form submission within event listener.

Cheers

@andtankian
Copy link
Author

andtankian commented Nov 29, 2018

Thank you for replying.

The problem I'm having is about the Validation form submit event handler that is calling form.submit(). So doesn't matter if I event.preventDefault() cause although submit event handler is successfully prevented in my custom handler, the Validation form submit event handler is still invoked again.
For obvious reasons, browsers prevent these handlers to be executed eternally, so the submit is actually done regardless of my custom prevent default.

Do you have any ideas?

Thank you very much.

@Mevrael
Copy link
Owner

Mevrael commented Nov 29, 2018

Thank you for notes.

Well, I suppose easiest option in that case would be to add onSubmit(form, promise / callback) method into Validation component and adjust init(). If it's a promise, wait till it's fulfilled. If it's a function, run it immediately.

In that case you could add additional actions before form is submitted like animations and you won't need to worry about checking if form is valid since it already is done for you inside if in init().

I am currently unavailable to do so. Maybe you could submit this commit and I would later push it to NPM.

Cheers

@juniorgarcia
Copy link

By now I'm also not able to perform a validation and send the form via Ajax when form is valid due this implementation detail. Also I didn't understand what you meant on

[...] add onSubmit(form, promise / callback) method into Validation component and adjust init().

preventDefault(); didn't work in any way.

I've searched on source code but didn't find references to this onSubmit method.

@andtankian andtankian closed this as not planned Won't fix, can't repro, duplicate, stale Jun 15, 2024
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