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

Print warning instead of error when using async #2827

Open
ccjruemenapf opened this issue Apr 19, 2017 · 11 comments
Open

Print warning instead of error when using async #2827

ccjruemenapf opened this issue Apr 19, 2017 · 11 comments
Labels
enhancement improvements in current API

Comments

@ccjruemenapf
Copy link

Hi Folks,
i would be nice, if there will be a possibility to create warnings instead of errors when using the async validation.
And if i am not wrong only asyncErrors exists and no asyncWarnings.

We want to build async uniqueness checks and show a warning not an error, if the endpoint sad - Nope.

Is there a chance or a plan to get a feature like this?

Greetings and thank you
Jan

@gustavohenke gustavohenke added the enhancement improvements in current API label Apr 19, 2017
@griffinmichl
Copy link
Contributor

Agreed on this enhancement! I want it in an app I'm working on where there's a URL input field. I'd like to be able to warn users that we couldn't resolve the URL they input.

I'm gonna work on this if no one else is.

@kentandersen
Copy link

kentandersen commented May 31, 2017

It would be great if this could have the same api as asyncValidate.
For example:

reduxForm({
  form: 'asyncWarn',
  validate,
  asyncValidate,
  asyncValidateBlurFields: ['username'], // renamed from asyncBlurFields to prevent confusion
  asyncWarn,
  asyncWarnBlurFields: ['username']
})(AsyncWarnForm)

asyncBlurFields should be an alias to asyncValidateBlurFields to preserve backwards compatibility

@SimonPNorra
Copy link

Hey @erikras and @griffinmichl,

do you have any idea for a workaround to support warnings in asyncValidations? We really need it in our current project and we are struggling finding a solution.

Thanks a lot.

Regards,
Simon

@terolepisto
Copy link

Has this have any progress? Is there a way to "push" any warnings otherway, like we have ability to change form values with this.props.change("foo","bar") ?

Like this.props.warning("foo","Double check Your Foo!") ?

@ghost
Copy link

ghost commented Jan 26, 2018

Has anyone found a workaround for this?

As @terolepisto says, if there's a way to manually add warnings to a form then external code could handle the async validation warning check and add to warning to the form when it returns.

@terolepisto
Copy link

terolepisto commented Jan 26, 2018 via email

@ghost
Copy link

ghost commented Jan 26, 2018

Thank you!

I hadn't thought of side-stepping redux-forms entirely, but that makes a lot of sense.

That gives me a workaround to keep me going.

I've posted this as a question to Stack Overflow, and it'd be of value to have your suggestion on there as an answer: https://stackoverflow.com/questions/48461100/how-can-i-show-a-redux-form-warning-as-a-result-of-async-validation

If SO isn't your thing then no worries, I'll add it as an answer in a few days with a link attributing it to here.

@gknapp
Copy link

gknapp commented Jun 25, 2018

Is there any example code for this?

Am I right in assuming you've a reducer updating the redux-form app state?
form.<formName>.syncWarnings.<field>: "Warning message"

Or some state elsewhere in the redux store passed as props?

Update: I've posted an answer on the above SO question about how I implemented async warnings on field blur.

@ughitsaaron
Copy link

ughitsaaron commented Sep 25, 2018

The async validation callback passes in dispatch as a second argument. If folks want to perform some kind of async validation that doesn't block submission but simply displays a warning message, you can use that dispatch to trigger an action that creates your own custom warning, e.g.,

import { addWarning } from '../actions/warning';
import { db } from '../db';

export const asyncValidate = async (values, dispatch) => {
  const someNonUniqueValueAlreadyExists = await db.findOne('someProperty', values.someValue);

  if (someNonUniqueValueAlreadyExists) {
    // just dispatch the action to add a warning to global state
    // don't throw any error here
    dispatch(addWarning('Is the user sure they want someValue here for someProperty?'));
  }
};

@szaboat
Copy link

szaboat commented Mar 25, 2019

Agreed on this enhancement! I want it in an app I'm working on where there's a URL input field. I'd like to be able to warn users that we couldn't resolve the URL they input.

I'm gonna work on this if no one else is.

@griffinmichl what was exactly agreed? I've bumped into this issue and could not find a proper solution and thinking about implementing it. There were two options discussed

  • have a new api and expose the asyncWarn and asyncWarnBlurFields
  • return a promise in the asyncValidation with warnings in it

I don't see what would be the preferred way. I lean towards the new API because warnings and validations are already separated on the sync API.
Thanks!

@jwanglof
Copy link

@szaboat I think that new APIs would be preferable with the reason you express, the validations are separated for the synchronous validation 👍

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

No branches or pull requests

10 participants