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

Add support for "multiple" select #41

Closed
cedricmessiant opened this issue Mar 1, 2016 · 9 comments
Closed

Add support for "multiple" select #41

cedricmessiant opened this issue Mar 1, 2016 · 9 comments

Comments

@cedricmessiant
Copy link
Contributor

I need to be able to create select fields with the possibilty to select multiple values.
I can work on it but I'm not sure which way I should go with jsonschema.

My intuition is to use a schema that looks like this :

myField: {
  type: 'array',
  title: 'My field',
  items: {
    type: 'string',
    enum: ['foo', 'bar'],
  }
}

maybe with an alternative widget multiselect for example.

What are your opinions about this ?

I will probably also need to support enumNames (See https://github.com/json-schema/json-schema/wiki/enumNames-(v5-proposal) )

@almet
Copy link
Contributor

almet commented Mar 1, 2016

I'll let @n1k0 ponder, he's our local json-schema expert (if you ask him, he'll say he's not, but that's lies)

@n1k0
Copy link
Collaborator

n1k0 commented Mar 1, 2016

@almet Haha, hmpf, thanks I guess.

Yes, we need to deal with a specific kind of array widget when the schema is constrained with an enum of strings (possibly numbers, integers, datetimes too) so we can render a select field (or a list of checkbox btw) instead of the regular ArrayField.

The only thing is that with such a schema, one might want to allow multiple occurrences of an allowed enum value in the resulting array, eg. ["foo", "bar", "foo"]. Reading this thread from 2009 about just this is slightly worrying though, as I couldn't find any followup to this specific problem. Hope it's just me who can't search for things.

Also, re enumNames support, there's #25 issue filed already.

@n1k0
Copy link
Collaborator

n1k0 commented Mar 1, 2016

Actually while googling for solutions I've just stumbled upon the Choices v5 proposal, which is probably something we'll want to support if it makes it to the spec eventually.

@n1k0
Copy link
Collaborator

n1k0 commented Mar 1, 2016

And so for ensuring a multiple choices field can't be mistaken for a multiple occurrences of choices field, there's is that UniqueItems proposal.

Edit: uniqueItems seems already used in http://json-schema.org/example1.html. We can probably safely bet on it being widely supported, though we should definitely check with the validation lib we use.

@cedricmessiant
Copy link
Contributor Author

Okay, so to sum up I can start working on supporting schemas like this :

myField: {
  type: 'array',
  title: 'My field',
  items: {
    enum: [
      'foo',
      'bar',
    ],
    type: 'string'
  },
  uniqueItems: true,
}

resulting on a multiple select (and maybe alternatively a list of checkboxes). Is that it ?

@n1k0
Copy link
Collaborator

n1k0 commented Mar 2, 2016

Is that it ?

That's a good summary of it, yes. Thanks you so much on planning to help and contribute!

@cedricmessiant
Copy link
Contributor Author

I just finished the work on this issue. However, I can not push my branch upstream to make my pull request. Could you give me the rigths on the repo or do you prefer that I make my pull request from a fork ?

@Natim
Copy link
Contributor

Natim commented Mar 3, 2016

Yes please do it from a fork, you could also give us some contributors roles on your fork if you want us to collaborate on your branch.

@n1k0
Copy link
Collaborator

n1k0 commented Mar 3, 2016

Fixed by #42.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants