redux-form icon indicating copy to clipboard operation
redux-form copied to clipboard

@@redux-form/BLUR action updates my value

Open SuEric opened this issue 5 years ago • 2 comments

Subject of the issue

I am using a custom component in my Field reduxForm, it is indeed passing the onChange property and the set of the value is working fine: CleanShot 2020-02-15 at 15 31 01@2x

However, when I leave the element redux-form BLUR action is dispatched and changes my value, why? CleanShot 2020-02-15 at 15 54 00@2x

custom components I am using:

Your environment

Steps to reproduce

  1. Go to https://codesandbox.io/s/redux-form-template-jgc8v
  2. Fill the UI of the input with (221) 212-1212
  3. Click outside input element
  • Notice how my value was changed
  • Notice how BLUR redux action was dispatched and changed my value

🎉 BONUS POINTS for creating a minimal reproduction and uploading it to GitHub. This will get you the fastest support. 🎉

Expected behaviour

BLUR action should NOT update the value at all? It reduces flexibility and confuses the prediction of reduxForm values.

Actual behaviour

BLUR action somehow is updating my value

SuEric avatar Feb 15 '20 21:02 SuEric

https://redux-form.com/8.3.0/docs/api/field.md/#-code-onblur-event-newvalue-previousvalue-name-gt-void-code-optional-

iamandrewluca avatar Feb 17 '20 12:02 iamandrewluca

Hi @SuEric , you should implement onBlur wrapper, that will resolve, value from your date input field, onBlur works fine in this case, in your input you have ONLY formatted string: '05/06/2016', NOT date object like Moment, Date or anything other, so your wrapper should looks like: ` const handleInputBlur = (event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => { const { value } = event.target; props.input.onBlur(parseDateToStringBlur(value)); };

const parseDateToStringBlur = (date: string): string | null => { if (date) { const momentDate = moment(date, 'dd/mm/yyyy', true); const isMomentDateValid = momentDate.isValid(); if (isMomentDateValid) { return momentDate.format() } return null; }; `

OVBondHUB avatar Jul 03 '20 14:07 OVBondHUB