Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation for defaultValue of FieldProps is not matching implementation #1015

Open
mauron85 opened this issue Dec 8, 2022 · 0 comments

Comments

@mauron85
Copy link

mauron85 commented Dec 8, 2022

Are you submitting a bug report or a feature request?

bug report

What is the current behavior?

The documentation for Field defaultValue states:

The value of the field upon creation. This value is only needed if you want your field be dirty upon creation (i.e. for its value to be different from its initial value).

So assumption is that to mark field as initially dirty we can set different defaultValue and initialValue.

For example:

<Field name={name} defaultValue={false} initialValue={true} />

What is the expected behavior?

Field defaultValue is only used when both form and field level initialValue are undefined. thus Field is not marked dirty, when initialValue is not undefined.

Current implementation:
https://github.com/final-form/final-form/blob/main/src/FinalForm.js#L908

        // only use defaultValue if we don't yet have any value for this field
        if (
          fieldConfig.defaultValue !== undefined &&
          fieldConfig.initialValue === undefined &&
          getIn(state.formState.initialValues, name) === undefined &&
          noValueInFormState
        ) {
          state.formState.values = setIn(
            state.formState.values,
            name,
            fieldConfig.defaultValue,
          );
        }

Sandbox Link

What's your environment?

React Final Form: 6.5.9

Other information

@mauron85 mauron85 changed the title Documentation defaultValue of FieldProps is not matching implementation Documentation for defaultValue of FieldProps is not matching implementation Dec 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant