Material: Can we make the error detail for textfields dynamic ?

Created on 10 Jan 2018  路  6Comments  路  Source: CosmicMind/Material

When the user is typing email : If the email is not in Regex format then it should the error ("invalid") automatically and when the email is again edited in Regex format then the error must be removed automatically while editing. Is it possible to do using this library ??
Just like as shown in screenshots below for Email field :

simulator screen shot - iphone 8 - 2018-01-10 at 21 48 20
simulator screen shot - iphone 8 - 2018-01-10 at 21 49 22

enhancement feature request good first issue help wanted material question

All 6 comments

You can do this using the delegation methods associated with the TextField. There is not a validation check for the values added, at least not at the moment. It would be a good feature though, and has been noted prior. I will add a feature request tag to this and make a sample or build it into Material. Thank you!

@danieldahan @Maddy10

Just wanted to add my two cents 馃槃

Validation should live outside of the framework as there are too many types of fields and validations. Ideally you would have a protocol to enable such functionality.

protocol TextFieldValidator {
func validateTextField()
}

protocol EmailTextFieldValidator: TextFieldValidator {}
protocol PhoneTextFieldValidator: TextFieldValidator {}

Then you can conform to your protocol when you need to validate a specific field and implement the validateTextField signature.

This also ensures that you keep your code dry and don't create needless subclasses of TextField.

Let me know if this makes sense - otherwise I can make a sample.

Best!

I agree @adamdahan. Are you suggesting to leave this outside of Material for now?

Made PR for this #1082

1082 is merged in, so next release gonna have this feature. For the usage guide see the PR description. Thank you!

I am going to close this issue as the PR is merged in. Let's focus on tomorrow making a release.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aleufms picture aleufms  路  6Comments

nthtrung09it picture nthtrung09it  路  5Comments

tskulbru picture tskulbru  路  6Comments

davidevincenzi picture davidevincenzi  路  5Comments

timoschwarzer picture timoschwarzer  路  4Comments