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

SimpleSchema: minCount arrays with options set empty checkboxes #691

Closed
danyhiol opened this issue Mar 11, 2020 · 4 comments · Fixed by #695
Closed

SimpleSchema: minCount arrays with options set empty checkboxes #691

danyhiol opened this issue Mar 11, 2020 · 4 comments · Fixed by #695
Assignees
Labels
Type: Bug Bug reports and their fixes

Comments

@danyhiol
Copy link

When defining an array schema with minCount and options, AutoForm renders the field with empty checkboxes.
Consider the following schema:

members: {
    type: Array,
    minCount: 2, 
  },
  "members.$": {
    type: String,
    uniforms: {
       options: [{label: "Label1", value: "val1"}, {label: "Label2", value: "val2"}]
    }
}

On the playground, this will result in a SelectField with 2 empty checkboxes. More over, no validation will be apply even taught no options is choosen when submitting the form. Meaning the array field is prepopulated with null values that are consider as valid from the schema.

  1. The members' array should not be populated with null values when using minCount. It should be empty and validated.
  2. The UI should not display empty checkboxes. Just like with null values, it should be empty and validated.
@kestarumper
Copy link
Member

Hi @danyhiol,

We've patched displaying empty boxes, but still, you should include the initialValue parameter inside your schema because uniforms cannot infer the default value of array elements used to produce an initial state of the form because SimpleSchema does not support that. A quick fix to you schema would be the following

new SimpleSchema({
  members: {
    type: Array,
    minCount: 2,
    uniforms: {
       initialValue: []
    }
  },
  "members.$": {
    type: String,
    uniforms: {
       options: [{label: "Label1", value: "val1"}, {label: "Label2", value: "val2"}]
    }
  }
})

You can also check it on playground here.

@danyhiol
Copy link
Author

@kestarumper that's great.
The workaround I haded was to initialize the members array it on the client with [], because using defaultValue: [] had no effect. I was actually thinking using deafautlValue would have the same effect as using initialValue.
Thanks for the fix.

@danyhiol
Copy link
Author

@kestarumper sry but i'll have to disturb you again with another issue that might be related to this one.

check this schema:

new SimpleSchema({
  members: {
    type: Array,
    minCount: 2,
    uniforms: {
       initialValue: [],
       mode: "tags",
       allowClear: true,
       options: []
    }
  },
  "members.$": {
    type: String,
    regEx: SimpleSchema.RegEx.EmailWithTLD,
  }
})

Playground

The regEx (regEx: SimpleSchema.RegEx.EmailWithTLD) validation is not applied inline. Without the ErrorsField, the user won't know why the form submission button is deactivated.

@kestarumper
Copy link
Member

Hi @danyhiol,

After the initial investigation, we've identified that's a problem with a field and how it displays its errors. Please create a separate issue for that. Thanks for pointing that out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Bug reports and their fixes
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants