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

Use CustomAutoField example with nested fields? #181

Closed
Gervwyk opened this issue Feb 3, 2017 · 4 comments
Closed

Use CustomAutoField example with nested fields? #181

Gervwyk opened this issue Feb 3, 2017 · 4 comments
Assignees
Labels
Type: Feature New features and feature requests

Comments

@Gervwyk
Copy link
Contributor

Gervwyk commented Feb 3, 2017

I'm trying to implement the CustomAutoField example but having trouble with with nested fields since CustomAuto is not called for nested fields. Schema definitions like:

  'chartCursor.cursorColor':{
      type: String,
      label: 'Cursor color',
      defaultValue: '#888',
      uniforms: {
        fieldComponent: 'color'
      }
    }

and

  'bands.$.color':{
    type: String,
    label: 'Band color',
    defaultValue: '#888',
    uniforms: {
      fieldComponent: 'color'
    }
  }

Although works well for top level fields. Is there a better way to do this? or why is CustomAutoField not executed for nested fields?

I tested this for BS3 and antd theme.

@radekmie radekmie self-assigned this Feb 3, 2017
@radekmie radekmie added the Type: Feature New features and feature requests label Feb 3, 2017
@radekmie
Copy link
Contributor

radekmie commented Feb 3, 2017

Well, it's not a bug, rather a new feature. Currently, NestField (and others) are simply importing nearest AutoField and using it - autoField prop being used only at the top level. There is no easy way to do it now, but I'll add it to the roadmap.

@radekmie
Copy link
Contributor

Hey, @Gervwyk! It've been a while, but I've finally came to an idea. I'd introduce autoField option to connectField:

const CustomAuto = props => ...;
const CustomAutoField = connectField(CustomAuto, {autoField: true, ensureValue: false, includeInChain: false, initialValue: false});

It will mark this field as an AutoField (or it's replacement). This information will be passed down the context, so every field will know, what the current AutoField is. There's only one flaw...

<AutoField name="x">
    <Auto name="x" ...>
        <CustomAutoField name="x" ...>
            <CustomAuto name="x" ...>
                ...
            </CustomAuto>
        </CustomAutoField>
    </Auto>
</AutoField>

Yep, that's it. We can't replace usage of default AutoField with CustomAutoField, so it has to be nested.

What do you think?

@radekmie
Copy link
Contributor

Other idea.
Introduce itemProps in NestField like in ListField. Then:

const schema = new SimpleSchema({
    tags: {
        type: [String],
        uniforms: {
            itemProps: {
                component: CustomAutoField
            }
        }
    }
});
// Then...
<AutoForm autoField={CustomAutoField} schema={schema} />

Will work as expected.

@Gervwyk
Copy link
Contributor Author

Gervwyk commented Feb 17, 2017

Great! The second option seems easy to implement and fits well with current model. Thanks! Guess this one is finally resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature New features and feature requests
Projects
Archived in project
Development

No branches or pull requests

2 participants