Skip to content

Conversation

kmarple1
Copy link

@kmarple1 kmarple1 commented Jul 9, 2018

MaterialUI's TextField accepts an error prop, but this wasn't being passed on by TextValidator. This PR rectifies that, allowing the error state to be set manually. This makes sense, as you can already set the helperText manually.

@NewOldMax
Copy link
Owner

Hi,
can you give a real case when this is really needed?

@kmarple1
Copy link
Author

kmarple1 commented Jul 10, 2018

Sure. Basically, it's needed any time you need to perform validation that the TextValidator itself can't handle, and want to use the helperText to display an error message.

For instance, the project I'm on now has a form to create a team. When you submit it, there's a server-side check to ensure the team name isn't a duplicate. If we get back an error, we want to display it at the corresponding field, so using the helperText for that field makes sense. Right now, you can set the helperText, but it will be gray instead of red, as you can't set the error state.

There are, of course, other ways to display an error, but using the field's own error/helperText props is the simplest, and it's the way you would use material-ui's TextField if it weren't wrapped. My current solution has been to clone the TextValidator component locally and make the same changes present in this PR (plus adding your license as a block comment).

Note that older versions of material-ui's TextField had an errorText prop for this purpose (which is still reflected in your package documentation), but the newer versions don't. You have to use helperText + error if you want the same result. This change should probably be made to SelectValidator as well, since it's in the same boat.

@NewOldMax
Copy link
Owner

Can you made this change for select too?

@kmarple1
Copy link
Author

Done.

@NewOldMax NewOldMax merged commit 758238a into NewOldMax:master Jul 11, 2018
@NewOldMax
Copy link
Owner

Thanks for your work!

@kmarple1
Copy link
Author

You bet. Any idea when it will hit npm?

@NewOldMax
Copy link
Owner

This or next week

@NewOldMax
Copy link
Owner

@kmarple1 released in 2.0.1

@VGamezz19
Copy link

oo m8, what about passing error text!!?

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

Successfully merging this pull request may close these issues.

3 participants