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
How do you think I could do this without a strange call of field.handleChange((v) => v)? The approach described in #743 is not working because my array field is not dirty. The field.validate('change') call just doesn't do anything. This is my code that works, but I don't like to change the array field with the same value to trigger validation:
<form.Fieldname="barcodes"mode="array"validators={{onChange: barcodesFieldValidator,onMount: barcodesFieldValidator,}}>{(field)=>{return(<div>{field.state.value.map((value,i)=>{return(<divstyle={{display: 'flex',flexDirection: 'row'}}key={value.id}>{value.externalBarcode}<form.Fieldname={`barcodes[${i}].enabled`}>{(subField)=>{return(<div><inputkey={`${value.id}-${subField.state.value}`}type="checkbox"checked={subField.state.value ?? false}onChange={(e)=>{subField.handleChange(!subField.state.value);// To make meta of the 'barcodes' field updated (make it dirty, touched, etc.)field.handleChange((v)=>v);}}/></div>);}}</form.Field></div>);})}</div>);}}</form.Field>// ValidatorconstbarcodesFieldValidator=(props: {value: Barcode[]})=>{returnprops.value.some((itm)=>itm.enabled) ? UNDEF : '-';};
In general, I think an array field should be considered dirty if any child element has been modified. I was very surprised to find out that this is not the case :)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
How do you think I could do this without a strange call of
field.handleChange((v) => v)
? The approach described in #743 is not working because my array field is not dirty. Thefield.validate('change')
call just doesn't do anything. This is my code that works, but I don't like to change the array field with the same value to trigger validation:In general, I think an array field should be considered dirty if any child element has been modified. I was very surprised to find out that this is not the case :)
Beta Was this translation helpful? Give feedback.
All reactions