mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-15 17:02:38 +00:00
fix issue with async setState using Event.persist()
This commit is contained in:
@@ -56,6 +56,7 @@ const MetadataEditor = createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
handleFieldChange : function(name, e){
|
handleFieldChange : function(name, e){
|
||||||
|
e.persist();
|
||||||
const inputRules = validations[name] ?? [];
|
const inputRules = validations[name] ?? [];
|
||||||
const validationErr = inputRules.map((rule)=>rule(e.target.value)).filter(Boolean);
|
const validationErr = inputRules.map((rule)=>rule(e.target.value)).filter(Boolean);
|
||||||
this.setState((prevState)=>({
|
this.setState((prevState)=>({
|
||||||
@@ -63,7 +64,7 @@ const MetadataEditor = createClass({
|
|||||||
...(prevState.errs ?? {}),
|
...(prevState.errs ?? {}),
|
||||||
[name] : validationErr.length > 0 ? validationErr : undefined
|
[name] : validationErr.length > 0 ? validationErr : undefined
|
||||||
}
|
}
|
||||||
}));
|
}), ()=>{
|
||||||
if(Object.values(this.state.errs ?? {}).filter(Boolean).length === 0){
|
if(Object.values(this.state.errs ?? {}).filter(Boolean).length === 0){
|
||||||
e.target.setCustomValidity('');
|
e.target.setCustomValidity('');
|
||||||
this.props.onChange({
|
this.props.onChange({
|
||||||
@@ -77,6 +78,8 @@ const MetadataEditor = createClass({
|
|||||||
e.target.setCustomValidity(errMessage);
|
e.target.setCustomValidity(errMessage);
|
||||||
e.target.reportValidity();
|
e.target.reportValidity();
|
||||||
};
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user