Skip to content
This repository has been archived by the owner on Apr 17, 2019. It is now read-only.

DependentInput does not populate default values. #7

Closed
anuragagarwal561994 opened this issue Jun 21, 2017 · 9 comments
Closed

DependentInput does not populate default values. #7

anuragagarwal561994 opened this issue Jun 21, 2017 · 9 comments
Labels

Comments

@anuragagarwal561994
Copy link

When you use an input field inside DependentInput and mention a defaultValue, the value is not filled:
Checkout:
https://codesandbox.io/s/v3o03kZL

Instructions:

  1. Click on Comments
  2. Click on Create
  3. Click on Show Dependent.

The dependent field has a default value but it is not shown.

@djhi djhi added the bug label Jun 21, 2017
@pimschaaf
Copy link

I found that setting the default value on the dependent input instead and setting the source, will correctly set these props and propagate them to the nested input. E.g.:

<DependentInput source="appointmentTimeslot" dependsOn="planned" defaultValue={1}>
    <ReferenceInput source="appointmentTimeslot" reference="timeslots" allowEmpty={true} >
        <SelectInput optionText="name" optionValue="id" />
    </ReferenceInput>
</DependentInput>

@anuragagarwal561994
Copy link
Author

@pimschaaf Yes I checked and your solution is working but it is still a bug as it is a hack which will solve the problem when we have one field. In case of multiple fields we can not specify multiple sources or default values in dependent input.

@pimschaaf
Copy link

@anuragagarwal561994 I don't think <DependentInput> is meant to be wrapped around multiple inputs. @djhi can you confirm?

Using multiple dependent inputs, each wrapped around only one input, should work in your case.

@anuragagarwal561994
Copy link
Author

@pimschaaf I agree that from the examples it is not clear for dependent inputs to be used for multiple input elements. But won't it make sense, because I usually have more than 1 field, so instead of writing separate dependent inputs for them it is much clearer for me to write a single dependent input wrapper and place multiple components.

But I surely agree that it can be another way of seeing DependentInput, may be I got confused. At present, multiple input thing works inside DependentInput component but default works in your way but for a single component.

@djhi
Copy link
Contributor

djhi commented Jul 7, 2017

You can wrap multiple children inside a single DependentInput. I'm trying to figure out why the defaultValue is not working

@datafibers
Copy link

wish this got resolved soon

@djhi
Copy link
Contributor

djhi commented Aug 1, 2017

We're looking for a solution for this. Stay tuned :)

@djhi
Copy link
Contributor

djhi commented Aug 1, 2017

Should be resolved once https://github.com/marmelab/admin-on-rest/pull/913 is finished

@djhi
Copy link
Contributor

djhi commented Aug 2, 2017

This is resolved in the next branch of admin-on-rest which will be released as 1.3.0

@djhi djhi closed this as completed Aug 2, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants