Field Level Validation Falsely updates sync errors to Empty Object on Change Event alternatively
See original GitHub issueI have a weird problem with field level validation. I have attached the bug behavior in the screen share. I have a Field with simple field level validation which onChange dispatches “UPDATE_SYNC_ERRORS” alternatively with correct error object and empty error object(even when the error object should not be empty). If you check the video, it’ll be more clear. The field I was tinkering with in the video is the following
<Field
name={`${packagePriceFieldName}.unit_price`}
placeholder="Price Per Package"
label="Unit Price"
component={index === 0 ? StaticInput : CurrencyInput}
seed={baseUnitPrice}
validate={[required, currency]}
/>
Index is the element index in the array(in my case it would be 1) packagePriceFieldName is the parent field name(in my case it’s ‘package[0].package_price[1]’) baseUnitPrice is a prop which is only used when index is 0. (so unnecessary)
When I’m tinkering with the input, even the console logs say that validation is false and still after onChange an action is dispatched with empty error object incorrectly.
The two validation functions are as follows:
export const required = value => value ? undefined: 'Required';
export const currency = value => {
const validation = /^[1-9]\d*(((,\d{3}){1})?(\.\d{0,2})?)$/.test(value);
console.log("Currency", value);
console.log("validation", validation);
return validation ?
undefined : 'Invalid Amount';
}
I also have exported the action dispatched throughout the page into json from react redux devtools.
Here’s a link for the attachments. https://drive.google.com/open?id=0ByZzhBPM_O4LNzE3cXA2QjcxaFE
Issue Analytics
- State:
- Created 7 years ago
- Reactions:3
- Comments:8 (1 by maintainers)
Top GitHub Comments
@mqklin, even though the
validate
prop is documented like that, the examples demonstrate that you can use it as an array: https://redux-form.com/6.5.0/examples/fieldLevelValidationSome add on in @buzjuka 's answer: Reference for validate function must be same otherwise your field will go into loop of RegisterField and UnregisterField.