You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First argument: Dictionary like {fieldId1: value1, fieldId2: value2, ... , __FIELD_CHANGED__: fieldId}. FIELD_CHANGED key contains as value the last field that has changed its value.
onBlur: method triggered on each on blur:
First argument: fieldId that has triggered the blur event.
checkConstrainstsFactory is a function exported by the form builder that returns the native errors of the form based on the constraints defined in each field in the json.
checkCustomConstraints is a invented function that allows to extend the validation of the form builder adding some validation outside the form.
importFormBuilder,{checkConstrainstsFactory}from'@s-ui/react-form-builder'constonBlur=fieldId=>{constcheckCustomConstraints=({fieldId, fieldValue})=>{if(fieldValue==='prohibit_word')return{[fieldId]: ['No puede contener palabras prohibidas']}}setErrors(prevErrors=>{// get errors derived from the constraints defined in jsonconstnewNativeErrors=checkConstrainstsFactory(JSONBuilder)({for: fieldId})// get errors not defined in the json ('custom')constnewCustomErrors=checkCustomConstraints({
fieldId,fieldValue: adFields[fieldId]})consterrors={
...prevErrors,
...newNativeErrors,
...newCustomErrors}// set errorsreturnerrors})}return(<FormBuilderjson={json}onBlur={onBlur}errors={errors}/>)