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

Custom validity on MDCTextfield #1018

Closed
DBartsch opened this issue Jul 26, 2017 · 3 comments
Closed

Custom validity on MDCTextfield #1018

DBartsch opened this issue Jul 26, 2017 · 3 comments
Assignees

Comments

@DBartsch
Copy link

So, I'm having a MDCTextfield that is initialized automatically.

I want to validate it by myself and this can't be done with any pattern or max-/minlength attribute.

As far as I understood the documentation all that's to do is calling setCustomValidity with any string as a parameter, but after doing so the field isn't marked as invalid. getting the validation properties of the HTMLInputElement also doesn't show anything.

Am I missing something out or is something catching and reverting the invalid status?

Just giving the .mdc-textfield the class mdc-textfield--invalid is also not working because the field may get and lose it's focus afterwards again (i tested it without any focus changes, too).

@teoxoy
Copy link

teoxoy commented Jul 28, 2017

I would also like this feature to be implemented. Looking at the foundation class the validity is being set on blur. A better implementation would be to have a property 'setValidity' that you can set yourself and another variable 'useNativeValidityChecking' that will be true by default and when setValidity will be called it will become false. So this will not break current implementations of the textfield.
I will do a commit in my fork. And I would like to hear the opinion of a member of the project.

@teoxoy
Copy link

teoxoy commented Jul 28, 2017

The valid variable is just a setter. The only way to implement a getter in the foundation would require the adapter to have a function hasClass and check for this.adapter_.hasClass(INVALID); or an additional variable that keeps track of the validity.

@teoxoy
Copy link

teoxoy commented Jul 28, 2017

Should I submit a PR ?

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

3 participants