question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FormDataConsumer not working properly inside 'Filter'

See original GitHub issue

What you were expecting:

FormDataConsumer to be used in Filters, so that we can have a filter with subcat values filtered based on another filter with cat values.

What happened instead: The filter does not appear correctly:

image

Other information:

      <FormDataConsumer>
        {({ formData, ...rest }) =>
          formData.cat_id && (
            <ReferenceInput
              // key={formData.cat_id}
              label="ΥΠΟΚΑΤΗΓΟΡΙΑ" 
              source="subCat_id"
              reference="subCategories"
              filter={{ cat_id: formData.cat_id }}
              {...rest}
            >
              <SelectInput optionText="name" />
            </ReferenceInput>
          )
        }
      </FormDataConsumer>

Environment

  • React-admin version: v2.2

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

12reactions
dennes544commented, Dec 18, 2018

Found solution to filter based on another filter without FormDataConsumer

<ReferenceInput source="filialid" reference="filials">
            <SelectInput optionText="filialname"/>
        </ReferenceInput>

        {props.filterValues.filialid &&
        <ReferenceInput
            key={props.filterValues.filialid}
            source="cabinetid"
            reference="cabinets"
            perPage={200}
            filter={{ filialid: props.filterValues.filialid }}
        >
            <SelectInput optionText="cabinetname"/>
        </ReferenceInput>}

Works like a charm

7reactions
amayatskycommented, May 30, 2019

In case anyone cames in here wondering how to reset the dependent filter value, here is a solution:

<FormDataConsumer form={'filterForm'} alwaysOn source='stateId'>
      {({ formData, dispatch, ...rest }) => (
        <ReferenceInput
          resource={props.resource}
          source='stateId'
          reference='states'
          onChange={value => {
            dispatch(change('filterForm', 'districtId', null));
          }}
          allowEmpty>
          <SelectInput optionText='name' />
        </ReferenceInput>
      )}
    </FormDataConsumer>

    {(props.filterValues.stateId || props.filterValues.districtId) && (
      <ReferenceInput
        key={props.filterValues.stateId}
        source='districtId'
        reference='districts'
        filter={{ stateId: props.filterValues.stateId }}
        alwaysOn>
        <SelectInput optionText='name' />
      </ReferenceInput>
    )}
Read more comments on GitHub >

github_iconTop Results From Across the Web

FormDataConsumer Within Filter - react admin - Stack Overflow
EDIT: I have tried using the FormDataConsumer within a Filter and I could not get it to work. Using dev tools in the...
Read more >
Input Components - React-admin - Marmelab
Such components allow to update a record field and are common in the <Edit> and <Create> components, and in the List Filters. Inputs....
Read more >
React-select-fast-filter-options does not work properly-Reactjs
[Solved]-React-select-fast-filter-options does not work properly-Reactjs ... I use an asynchronous javascript function like fetch inside a FormDataConsumer ...
Read more >
CHANGELOG.md · 邹昊坤/marmelab-react-admin - Gitee.com
... format ([#2655](https://github.com/marmelab/react-admin/pull/2655)) ([fzaninotto](https://github.com/fzaninotto)) * Fix `<FormDataConsumer>` not working ...
Read more >
how to disable input field based on condition react - You.com
Its not data.valid .. its obj.valid in Input field ... <Button disabled={!activityChanged} loading={submitting} floated="right" positive type="submit" ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found