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

Conditional visibility not working when field order is changed #1385

Closed
jspannu919 opened this issue Jun 2, 2023 · 1 comment
Closed

Conditional visibility not working when field order is changed #1385

jspannu919 opened this issue Jun 2, 2023 · 1 comment

Comments

@jspannu919
Copy link
Contributor

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

@Hyperkid123
Copy link
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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants