Skip to content

Conditional visibility not working when field order is changed #1385

Closed
@jspannu919

Description

@jspannu919

In case of conditional visibility, if the parent field of a field comes after it in the schema then the conditional visibility doesn't works.Example:
This works (field 1 is visible)

fields: [
    {
      component: 'text-field',
      name: 'f2',
      label: 'Field 2',
     initialValue:'a'
    },
    {
      component: 'text-field',
      name: 'f1',
      label: 'Field 1',
      condition: {
        when: 'f2',
        is: 'a',
      },
    }
  ],

This doesn't (field 1 is not visible)
`fields: [

{
  component: 'text-field',
  name: 'f1',
  label: 'Field 1',
  condition: {
    when: 'f2',
    is: 'a',
  },
},{
  component: 'text-field',
  name: 'f2',
  label: 'Field 2',
 initialValue:'a'
},

],`

One of the solution to this is that we add the subscription for initial along with value here:

  <Field name={name} subscription={{ value: true }}>
      {({ input: { value } }) => (
        <ConditionTriggerDetector

But the react final forms also have a bug due to which the field api doesn't re-renders on change of initial Value. Raised PR(final-form/react-final-form#1034), but there is no response from their end.

Is there any other way to fix this issue?
CC: @Hyperkid123 @rvsia

Activity

Hyperkid123

Hyperkid123 commented on Jun 5, 2023

@Hyperkid123
Member

Yeah I was about to ask why the values subscription does not cover the initial value changes. As it also changes the value. At least there is a "sort of clean" work around.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Conditional visibility not working when field order is changed · Issue #1385 · data-driven-forms/react-forms