Fill the gap for unified mode to handle complex structure like separated mode
See original GitHub issueHi there!
Sorry for the long issue, but itās the only way I can explain what Iām trying to do. š
Iām trying to create a component that looks like this:

Iāve chosen to use the āunifiedā fields definition, because it seems to make more sense for large forms that have a lot of values versus keeping them separated. Hereās what the definition looks like for the field.
{
name: 'sending_ips',
label: 'Sending IPs',
rules: 'required',
value: [],
},
Based on what Iāve seen in the documentation, this is correct? If I look at the Form dev tools, it properly has captured the values as an array:

Iāve created a component that I use to render the fields and Add/Remove them as needed. I simply pass in the field
prop like so:
<InputMultiple
field={form.$('sending_ips')}
inlineLabel
/>
And the component itself:
const InputMultiple = ({ field }) => {
return (
<Box>
<Label field={field} inlineLabel>
{field.map((f) => {
return f && (
<Box className="pt-input-group" mb={1} key={f.id}>
<Input field={f} key={f.key} showLabel={false} />
<Button
className="pt-minimal"
intent={Intent.DANGER}
onClick={f.onDel}
iconName="cross"
/>
</Box>
);
})}
<Button iconName="plus" onClick={field.onAdd} text="Add Value" />
<ErrorBlock field={field} />
</Label>
</Box>
);
};
export default observer(InputMultiple);
Iāve copied some of this code from your demo-examples (which are great, btw). The issue Iām having is that:
{field.onAdd}
does not do anything. The removal of individual fields works as expected inside of themap
.- The validation rules are not applied to the individual fields
- If I change the field definitions to use the āseparateā style - and use
sending_ips[]
, thefield.onAdd
works correctly.
Am I missing something, or is it not possible to achieve this with the unified field definition style? Iāve read over the FAQs and Iām not sure my question has been answered. I believe my issue is similar to https://github.com/foxhound87/mobx-react-form/issues/186, except Iām just trying to create multiple standard input fields to render the values into.
Thanks again!
Issue Analytics
- State:
- Created 7 years ago
- Comments:11 (7 by maintainers)
HI @mwarger
Right now the big issue is that with the unified mode you cannot specify deep nested fields, for example, if I have an array of objects. But I will figure it out!
Iām using the unified props and converting it in to a separate props using something like:
The result can be passed to the form: