barseghyanartur / django-fobi

Form generator/builder application for Django done right: customisable, modular, user- and developer- friendly.
https://pypi.python.org/pypi/django-fobi
484 stars 112 forks source link

Select multiple element #202

Closed hernanfila closed 5 years ago

hernanfila commented 5 years ago

Hi @barseghyanartur , I am getting an issue when selecting more than one item in the select multiple element:

image

Select one or more: image

In the server, I want to read selected values, but it seems to be taking only one item: When I print request.POST.dict(), I see only one value in the select Multiple field.

Do you know how can I get all selected values?

Thank you

barseghyanartur commented 5 years ago

@hernanfila:

You're doing it in a wrong way. Check this:

barseghyanartur commented 5 years ago

@hernanfila:

FYI, https://github.com/barseghyanartur/django-fobi/tree/stable/src/fobi/contrib/plugins/form_elements/fields/select_multiple/

By default, the submitted form value of select_multiple elements is label (human readable representation of the value chosen). However, that part of the behaviour has been made configurable. You can choose between the following options:

Consider the following list of (value, label) choices (the first element in the tuple is value, the second element is label):

[
    ('alpha', 'Alpha'),
    ('beta', 'Beta'),
    ('gamma', 'Gamma'),
]
- "val": `value` (example: "alpha").
- "repr" (default): `label` (example: "Alpha").
- "mix": `value (label)` (example: "Alpha (alpha)").

Simply set the FOBI_FORM_ELEMENT_SELECT_MULTIPLE_SUBMIT_VALUE_AS assign one of the following values: "val", "repr" or "mix" to get the desired behaviour.

That applies to all multi-value plugins.