0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-03 23:32:58 +00:00

Debounce validation popup

This commit is contained in:
Trevor Buckner
2025-02-13 15:01:35 -05:00
parent df563b9294
commit bf297939dc
2 changed files with 9 additions and 6 deletions

View File

@@ -79,7 +79,7 @@ const Combobox = createClass({
if(!e.target.checkValidity()){ if(!e.target.checkValidity()){
this.setState({ this.setState({
value : this.props.default value : this.props.default
}, ()=>this.props.onEntry(e)); });
} }
}} }}
/> />

View File

@@ -68,6 +68,11 @@ const MetadataEditor = createClass({
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);
const debouncedReportValidity = _.debounce((target, errMessage) => {
callIfExists(target, 'setCustomValidity', errMessage);
callIfExists(target, 'reportValidity');
}, 300); // 300ms debounce delay, adjust as needed
// if no validation rules, save to props // if no validation rules, save to props
if(validationErr.length === 0){ if(validationErr.length === 0){
callIfExists(e.target, 'setCustomValidity', ''); callIfExists(e.target, 'setCustomValidity', '');
@@ -82,8 +87,8 @@ const MetadataEditor = createClass({
return `- ${err}`; return `- ${err}`;
}).join('\n'); }).join('\n');
callIfExists(e.target, 'setCustomValidity', errMessage);
callIfExists(e.target, 'reportValidity'); debouncedReportValidity(e.target, errMessage);
return false; return false;
} }
}, },
@@ -276,8 +281,6 @@ const MetadataEditor = createClass({
}); });
}; };
const debouncedHandleFieldChange = _.debounce(this.handleFieldChange, 500);
return <div className='field language'> return <div className='field language'>
<label>language</label> <label>language</label>
<div className='value'> <div className='value'>
@@ -288,7 +291,7 @@ const MetadataEditor = createClass({
onSelect={(value)=>this.handleLanguage(value)} onSelect={(value)=>this.handleLanguage(value)}
onEntry={(e)=>{ onEntry={(e)=>{
e.target.setCustomValidity(''); //Clear the validation popup while typing e.target.setCustomValidity(''); //Clear the validation popup while typing
debouncedHandleFieldChange('lang', e); this.handleFieldChange('lang', e);
}} }}
options={listLanguages()} options={listLanguages()}
autoSuggest={{ autoSuggest={{