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

uncaught error with invalid model #58

Open
boesi opened this issue Aug 8, 2022 · 3 comments
Open

uncaught error with invalid model #58

boesi opened this issue Aug 8, 2022 · 3 comments

Comments

@boesi
Copy link

boesi commented Aug 8, 2022

Hi

If I put an invalid value in my form, I get a nice error message in my template and the submit function isn't called. But I also get an error message in the developer console:

bs-form.js:28 Uncaught (in promise) Error
    at BsFormWithChangesetValidationsSupport.validate (bs-form.js:28:1)
validate                            @ bs-form.js:28
Promise.then (async)
iterations                          @ backburner.js:18
[...stack trace...]

How can I catch this error? And why do I even have to catch this error? Or do I miss something else?

Thanks for your help and all your work

@boesi
Copy link
Author

boesi commented Aug 9, 2022

I've found the cause: I want a form, that is automatically submitted, when the input field loses focus.

For this I've build the form this way:

<BsForm @model={{changeset this.item this.validations}} @onSubmit={{this.saveItem}} as |form|>
    <form.element @property=... as |el|>
        <el.control {{on "focusout" form.submit}}/>
    </form.element>
</BsForm>

If I use a regular submit button, I don't get the error message in the console.

I could call another action in the focusout event handler, and check myself if the model is valid:

        <el.control {{on "focusout" (fn this.otherAction ...)}}/>

... but how do I get the changeset?

If I'm interpreting the documentation for the submit action correctly, my approach should (or could?) work. Ember-Changeset would be pretty ideal for this "no-save-button-style".

@jelhan
Copy link
Collaborator

jelhan commented Aug 9, 2022

If I'm interpreting the documentation for the submit action correctly, my approach should (or could?) work.

Yes. It should work. Do you have time to investigate why it is not working? A reproduction would be very helpful to understand what is happening. Also would be interesting to know if it is specific to Ember Bootstrap Changeset Validations. Or if it's a general issue with Ember Bootstrap's validation API. And if it's happening always if using form.submit or specific to timing of modifiers / runloop. To be honest I have no clue yet, what might happen.

@boesi
Copy link
Author

boesi commented Aug 10, 2022

I have created a simple test repository: Auto Submit

In my actual project I'am still using Bootstrap 4, but as you can see Bootstrap 5 shows the same error.

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

2 participants