validate on blur for class component
See original GitHub issueI’m writing my React components using the new ES6 class syntax and the Formsy.HOC
method. I’ve tried implementing validate on blur, but have been unable to get it to work.
Whenever I try typing into the input, no values get set. Here is my code:
import React, { Component } from 'react';
import { HOC } from 'formsy-react';
class FormInput extends Component {
changeValue(event) {
if (this.props.getErrorMessage() != null) {
this.props.setValue(event.currentTarget.value);
} else {
if (this.props.isValidValue(event.target.value)) {
this.props.setValue(event.target.value);
} else {
this.setState({
_value: event.currentTarget.value,
_isPristine: false
});
}
}
}
blurValue(event) {
this.props.setValue(event.currentTarget.value);
}
render() {
return (
<div>
<input type="text" onBlur={this.blurValue.bind(this)} onChange={this.changeValue.bind(this)} value={this.props.getValue() || ''} />
);
}
};
export default HOC(FormInput);
I’m sure the example on the wiki works using mixins, but how can I get it to work with the setup I have above?
Issue Analytics
- State:
- Created 7 years ago
- Comments:6
Top Results From Across the Web
ReactJS - using onBlur to validate email field - Stack Overflow
I think the right way to do so is by using internal state of the component: class EmailComponent extends React.
Read more >onBlur validation with react-material-ui-form-validator · GitHub
onBlur validation with react-material-ui-form-validator - Component.jsx. ... export default class SomeComponent extends React.Component {. constructor() {.
Read more >Client-side Checking with React.js JSX Events Using onBlur
Capturing and applying logic to an HTML onBlur event allows other UI interactivity. This guide will hook in logic with an onBlur event...
Read more >How to change validation behavior on blur event of lightning ...
I want to validate only at submitting form data via REST API. How can I achieve this? Sample template is simple as below....
Read more >onblur Event - W3Schools
The onblur event is often used with form validation (when the user leaves a form field). Focus Based Events. Event, Description, Bubbles. focus,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Give this a try:
@aesopwolf Really cool, this works. Thanks!