kettanaito/react-advanced-form

handleFieldChange returns whatever controlled "onChange" returns as the next field state

kettanaito opened this issue · 0 comments

Environment

  • react-advanaced-form: 1.6.5

What

Current behavior

return dispatch(
onChange,
{
event,
nextValue,
prevValue,
fieldProps,
fields,
form,
},
form.context,
)
}

This returns anything controlled change handler returns (i.e. async action). Later, depending on the returned payload from the handleFieldChange handler, Form.handleFieldChange dispatches its updateFieldWith.

if (nextFieldProps) {
await this.updateFieldsWith(nextFieldProps)
}

This results into returned payload set as the field's state, which is wrong.

Expected behavior

  • Only valid field state is set in the field's state

How

  • Dispatch the onChange handler first, then return short-circuit