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

Recommendation for multi-checkbox inputs? #33

Closed
zeroasterisk opened this issue Jun 17, 2016 · 14 comments
Closed

Recommendation for multi-checkbox inputs? #33

zeroasterisk opened this issue Jun 17, 2016 · 14 comments
Assignees
Labels
Type: Feature New features and feature requests Type: Question Questions and other discussions

Comments

@zeroasterisk
Copy link
Contributor

What is your recommendation for multi-checkbox inputs?
Ideally I want to return an array of values, for all checked checkboxes, and specify them as uniforms.options

@radekmie radekmie self-assigned this Jun 17, 2016
@radekmie radekmie added the Type: Question Questions and other discussions label Jun 17, 2016
@radekmie
Copy link
Contributor

It should be easy but on the second thought... It's doable in a hacky way but it's not what we want. It seems like there is a need for a new component - same as <SelectField /> but with checkboxes instead.

@radekmie
Copy link
Contributor

I've got another idea - how about a checkbox (or checkboxes) prop on <SelectField />? It will be easier to switch between them - it's only an additional prop in schema or form. What do you think?

@zeroasterisk
Copy link
Contributor Author

I agree, that is how I've seen it done with other form systems. Then the
schema type needs to support an array, and we are all set.

On Sat, Jun 18, 2016, 7:00 AM Radosław Miernik notifications@github.com
wrote:

I've got another idea - how about a checkbox (or checkboxes) prop on ? It will be easier to switch between them - it's only an additional
prop in schema or form. What do you think?


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#33 (comment), or mute
the thread
https://github.com/notifications/unsubscribe/AABbfh0yG6uML5_HX0cEemluj2OXHFLdks5qM8_MgaJpZM4I4fIp
.

@radekmie
Copy link
Contributor

I'll take care of this now.

@radekmie radekmie added the Type: Feature New features and feature requests label Jun 18, 2016
@macrozone
Copy link
Contributor

It's the same for radio-buttons:

List of radiobuttons are equal to select with single value

List of checkboxes are equal to select with multivalue

@GoaGit
Copy link

GoaGit commented Sep 25, 2016

Dear @radekmie,

As I trying to allow multiple values for a single field, I am running into trouble. A list of checkboxes shows up in the client, but I can only select a sinlge value (single checkbox checked). I thought the checkboxes prop in the schema should do the trick. Any suggestions how should I change the implementation?

I am using uniforms version 1.0.1

// Schema definition
// Should allow for Category to hold multiple values in an array: [ 1, 3 ] of [ 1, 3, 4 ]
Category: {
    type: Number,
    optional: true,
    allowedValues: [ 1, 2, 3, 4 ],
    uniforms: {
        label: "Category",
        checkboxes: true,
        options: function(){
            return [
                    { label: "A", value: 1 },
                    { label: "B", value: 2 },
                    { label: "C", value: 3 },
                    { label: "D", value: 4 }
                    ]
        }
    }
}
// Form definition
<AutoForm
    schema={ CategorySchema }
    onSubmit={ ( doc ) => console.log(doc) }
>
    <SelectField name="Category" />
</AutoForm>

@zeroasterisk
Copy link
Contributor Author

zeroasterisk commented Sep 25, 2016

Try type=[Number]

@radekmie
Copy link
Contributor

Yeah @GoaGit - @zeroasterisk is right.

Your field has a Number type which allows only one number, not an array of numbers. You should use [Number] instead.

@GoaGit
Copy link

GoaGit commented Sep 25, 2016

Thanks @zeroasterisk, @radekmie, this is the appropriate way. However, my problem appears to be SimpleSchema related. The example provided is based on schema that is created from a base schema. SimpeSchema provides the pick method to create a new schema:

// MyCollection has the baseschema attached to it. I select one field "Category" in this case:

CategorySchema = MyCollection.schema.pick( 'Category' )

This throws an error because of the type: [ Number ] .

I duplicated the schema for now and this works.

@radekmie
Copy link
Contributor

@zeroasterisk
Copy link
Contributor Author

Yeah - you can't "pick" for an nested/arrayed fields.

I've been splitting the object you pass into the SimpleSchema constructor into it's own "config" object... I can pick from those, and then pass into various SimpleSchema's with my composed/picked/varried configurations, at the end of the file.

eg:

const MyConfig = {
  thing: { type: [Number] }
};
const AltConfig = _.pick(MyConfig, 'thing');
const MySchema = new SimpleSchema(MyConfig);
const AltSchema = new SimpleSchema(AltConfig);

@GoaGit
Copy link

GoaGit commented Sep 25, 2016

Thanks @zeroasterisk, your suggestion works.

@radekmie: I don't now if it is related to the issue you mentioned.

(Note: Picking from array fields appears to be possible. E.g. this works for me:

...
field: { type: Array },
'field.$': { type: Object },
'field.$.item': { type: String }
...

followed by

export const NewSchema = MyCollection.schema.pick( 'field', 'field.$', 'field.$.item' );

and

<AutoForm
    schema={ NewSchema }
    onSubmit={ ( doc ) => console.log( doc ) }
>
    <SubmitField value="Save" />
    <ErrorsField />
    <ListField name="field">
        <ListItemField name="$"> 
            <TextField name="item" />
        </ListItemField>
    </ListField>
</AutoForm>

)

@radekmie
Copy link
Contributor

@GoaGit: that's the exact reason of this issue.

@GoaGit
Copy link

GoaGit commented Sep 30, 2016

@radekmie, confirmed. Thanks.

@Monteth Monteth added this to Closed in Open Source (migrated) Jun 24, 2021
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 Type: Question Questions and other discussions
Projects
Archived in project
Development

No branches or pull requests

4 participants