-
Notifications
You must be signed in to change notification settings - Fork 25
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
input element loses focus after typing #23
Comments
Could you share your sources, please? Examples in this repo works fine. |
I basically followed your tutorial on these sites: And thats the component where i've used it in.
|
I see. Try to move this out of the
|
Also, you can use |
Validation can be refactored like this: getValidatedLinks(){
const links = this.linkAll(); // or this.linkAll( 'attr1', 'attr2', ... ) if you need just the part of the state
links.name
.check( x => x.length >= 2, 'You forgot to type a name')
.check( x => x.indexOf( ' ' ) < 0, "The name you choose shouldn't contain spaces");
const emailRegexPattern = /^([\w.%+-]+)@([\w-]+\.)+([\w]{2,})$/i;
links.email
.check( x => x, 'You forgot to enter your email')
.check( x => x.match(emailRegexPattern), "Please enter a valid email adress");
links.password
.check( x => x.length >= 6, 'Your password should be min 6 characters long')
.check( x => x.match(/^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{6,}$/), 'Your Password should contain at least one digit');
return links;
}
render() {
const links = this.getValidatedLinks();
... |
Let me know if you'll have any further problems. I think I will update the tutorials to reflect the last version of the API. |
Also, in a real application you might want to create generic validation functions so they can be reused across the forms. Like this: // Do this once...
const emailRegexPattern = /^([\w.%+-]+)@([\w-]+\.)+([\w]{2,})$/i;
const isEmail = x => x.match(emailRegexPattern);
isEmail.error = "Please enter a valid email adress";
// and then just
const emailLink = this.linkAt( 'email' ).check( isEmail ); Much better, right? :) |
Or, simply function shouldBeEmail( link ){
link.check( x => x, 'You forgot to enter your email')
.check( x => x.match(emailRegexPattern), "Please enter a valid email adress");
return link;
} There are a lot of ways to make it look nicer than it is. |
Please, reopen if the suggestion about FormInput won't help. I'm pretty sure it will. |
Hey i'm trying to use your valueLink approach to validate my user inputs.
The issue i get is that the input elements lose focus when i type one character. So i have to click in the form a second time to write again. This happens after each character.
But there are good news. The validation itself works perfect.
I'm new to react, so it is also possible that i missed a major point.
The text was updated successfully, but these errors were encountered: