Skip to content
This repository has been archived by the owner on Aug 23, 2022. It is now read-only.

Custom control does not re-validate on submit / parent model change #1020

Closed
niawdeleon opened this issue Nov 18, 2017 · 1 comment
Closed

Comments

@niawdeleon
Copy link

niawdeleon commented Nov 18, 2017

The Problem

I have a custom control using React-Select as its component property. Even though the field was loaded with an initial value, the field is still reported as valid=false on submit. Its validity state is not recomputed after the change or on submit, in contrast to the other non-custom fields.

Steps to Reproduce

Here's what I understand is happening based on the redux log:

  1. When the form is mounted, setErrors is called on each field in the form. Since the fields are initially empty (thus violating the validators), each field's .valid property is set to false.
  2. Values are loaded (e.g. from DB)
  3. A second batch of setErrors is triggered. Somehow only the validity of non-custom controls are re-computed even though all of them have validators and all their values have changed. As a result, the non-custom controls have the correct validity state, but the custom controls have an incorrect validity state.
  4. When submit is called, the custom controls report validation errors despite having the correct values.

screen shot 2017-11-18 at 5 57 16 pm

In the screenshot above:

  1. initial rrf/setErrors on hotel.name
  2. initial rrf/setErrors on hotel.activities
  3. silent rrf/change on hotel (to load values)
  4. triggered rrf/setErrors on hotel.name
  5. MISSING rrf/setErrors on hotel.activities -- why?

Expected Behavior

When the form values change, the validity of custom controls are recomputed.

Actual Behavior

When the form values change, the validity of custom controls are not recomputed.

Reproducible Code Example

CodePen

Note that I am using actions.change instead of actions.load as a workaround to a previous issue (#952).

@niawdeleon niawdeleon changed the title Custom control does not re-validate on submit Custom control does not re-validate on submit / form change Nov 18, 2017
@niawdeleon niawdeleon changed the title Custom control does not re-validate on submit / form change Custom control does not re-validate on submit / parent model change Nov 18, 2017
@niawdeleon
Copy link
Author

niawdeleon commented Nov 18, 2017

@davidkpiano I'm trying to read the codebase but I'm having a hard time finding the mechanism by which each control in the form is validated when the entire form's model is validated. What calls the initial sequence of rrf/setErrors on each form control? And then after calling actions.change(model) on the form's model, another set of rrf/setErrors is triggered. Where does this happen?

Thanks

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant