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

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