mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-03 21:22:39 +00:00
don't save errs to state
This commit is contained in:
@@ -57,30 +57,27 @@ const MetadataEditor = createClass({
|
|||||||
|
|
||||||
handleFieldChange : function(name, e){
|
handleFieldChange : function(name, e){
|
||||||
e.persist();
|
e.persist();
|
||||||
|
|
||||||
|
// load validation rules, and check input value against them
|
||||||
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)=>({
|
|
||||||
errs : {
|
|
||||||
...(prevState.errs ?? {}),
|
|
||||||
[name] : validationErr.length > 0 ? validationErr : undefined
|
|
||||||
}
|
|
||||||
}), ()=>{
|
|
||||||
if(validationErr.length === 0){
|
|
||||||
e.target.setCustomValidity('');
|
|
||||||
this.props.onChange({
|
|
||||||
...this.props.metadata,
|
|
||||||
[name] : e.target.value
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
const errMessage = this.state.errs[name].map((err)=>{
|
|
||||||
return `- ${err}`;
|
|
||||||
}).join('\n');
|
|
||||||
e.target.setCustomValidity(errMessage);
|
|
||||||
e.target.reportValidity();
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
// if no validation rules, save to props
|
||||||
|
if(validationErr.length === 0){
|
||||||
|
e.target.setCustomValidity('');
|
||||||
|
this.props.onChange({
|
||||||
|
...this.props.metadata,
|
||||||
|
[name] : e.target.value
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// if validation issues, display built-in browser error popup with each error.
|
||||||
|
console.log(validationErr);
|
||||||
|
const errMessage = validationErr.map((err)=>{
|
||||||
|
return `- ${err}`;
|
||||||
|
}).join('\n');
|
||||||
|
e.target.setCustomValidity(errMessage);
|
||||||
|
e.target.reportValidity();
|
||||||
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
handleSystem : function(system, e){
|
handleSystem : function(system, e){
|
||||||
|
|||||||
Reference in New Issue
Block a user