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

Adding errors directly to fields #32

Closed
nyanpasu opened this issue May 17, 2021 · 6 comments
Closed

Adding errors directly to fields #32

nyanpasu opened this issue May 17, 2021 · 6 comments

Comments

@nyanpasu
Copy link

nyanpasu commented May 17, 2021

Could we add support for adding errors directly into the fields somehow?

A typical use case would be to handle errors from an API after it has been called.

@nyanpasu nyanpasu changed the title Adding errors directly to fields directly Adding errors directly to fields May 17, 2021
@nyanpasu
Copy link
Author

nyanpasu commented May 17, 2021

Neat, realized that the set and update functions of the store are also exported. Maybe a helper / util method would be nice to have, so that users can add errors without needing to handle the shape of the store.

But otherwise I can still handle this issue on my end. Cheers.

@chainlist
Copy link
Owner

Hi,

A v2 of svelte-forms has been released that fixes this use case.
Check out the new documentation website

@dextermb
Copy link

@chainlist I've just ran into this issue, looking through the v2 documentation I don't see anything about manually setting errors.

I've also noticed some of the sidebar links don't go to the right sections

@aniolekx
Copy link

This issue was closed, but it is still not clear how to add errors from server (or API). When I submit form, server side validation can return additinal errors related to particular field, how can I add these errors to field to render it? I have tested today several solutions but nothing was working. These errors from server were not rendered in form. This seems to be common requirement.

@aniolekx
Copy link

Hi,

A v2 of svelte-forms has been released that fixes this use case. Check out the new documentation website

can find anything related :/

@aniolekx
Copy link

async function set(field, forceValidation = false) { if (!isField(field)) { field = processField(get(store), [], { value: field }); } if (forceValidation || options.validateOnChange) { let validations = await getErrors(field, validators, options.stopAtFirstError); _set(processField(field, validations, { dirty: true })); } else { _set(processField(field, null, { dirty: true })); } }

ok, maybe I have found the problem, even when forceValidation is set to false, options.validateOnChange is triggering validation and overwrites my custom errors, unfortunately I cannot disable it because this will affect user experience, but I need a method to set it without triggering any validation, otherwise it will overwrite my custom errors, any suggestions?

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

4 participants