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

Show something while a field is untouched, when dirty replace by feedbacks #40

Open
lamontadams opened this issue Apr 2, 2019 · 2 comments

Comments

@lamontadams
Copy link

I hate to be a pest with stupid questions.... ;)

I'm looking for a way to show some helper text on an unvalidated field and then swap it out for FieldFeedback error messages when necessary. Is there an easy way to do that?

I thought <FieldFeedback when="valid" might do what I want, but that only seems to display after the form has been validated (which makes sense). I then tried to just apply a <FieldFeedback info/> with my helper text in it, but that also doesn't show up until after a validation (and even then looks just like an error message).

So I'm looking at tracking which fields are unvalidated or validdated-and-valid (either in state or via a bunch of refs) so I can show/hide some typography inside helperText... But that feels extra dirty, so I figured it was worth asking here -- Is there a better way to do what I'm after?

@tkrotoff
Copy link
Owner

tkrotoff commented Apr 2, 2019

show some helper text on an unvalidated field and then swap it out for FieldFeedback error messages when necessary. Is there an easy way to do that?

Good question. I didn't consider this use case. I'm looking at it, not easy actually.

@tkrotoff tkrotoff changed the title For material-ui, is there a way to show "everything's OK" helper text for unvalidated fields? Show something while a field is untouched, when dirty replace by feedbacks Apr 4, 2019
@tkrotoff
Copy link
Owner

tkrotoff commented Apr 4, 2019

For the moment, you have to handle this yourself.
Something like:

state = {
  fieldUntouched: true
};

handleChange(e) {
  this.setState({fieldUntouched: false});
}

handleReset() {
  this.setState({fieldUntouched: true});
}

<FieldFeedbacks for="field"> // Displayed when field has been validated, i.e dirty
  ...
</FieldFeedbacks>
{fieldUntouched ? <div>Help</div> : null}

If you have any other use case that is not handled by react-form-with-constraints, I would be glad to hear.
Thx.

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

No branches or pull requests

2 participants