Still on Drupal 7? Security support for Drupal 7 ended on 5 January 2025. Please visit our Drupal 7 End of Life resources page to review all of your options.Simple multiple select generated by custom entity form. See attached image.
This is the BaseFieldDefinition to replicate.
$fields['country'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Countries'))
->setDescription(t('Countries of this fee'))
->setSetting('target_type', 'country')
->setSetting('handler', 'default')
->setRequired(true)
->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE)
->setDisplayOptions('form', [
'type' => 'options_select',
]);
(Replace country target_type with "user", for example)
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | bootstrap-select_multiple_icon-2762091-5.patch | 1.17 KB | grimreaper |
| #3 | bootstrap-select_multiple_icon-2762091-3.patch | 3.04 KB | grimreaper |
| select_multiple_fail.png | 22.39 KB | estoyausente |
Comments
Comment #2
markhalliwellAh, that is indeed not good. I would say that we should just expand the CSS to include
:not([multiple]), but perhaps we should just remove the wrapper from the template entirely if multiple?Comment #3
grimreaperHello,
As there is no mean to affect the parent styling based on the children in CSS (maybe I missed a way), here is a patch that removed the wrapper.
I think it would have been better to keep the wrapper but that would have required JS.
Thanks for the review.
Comment #4
markhalliwellInstead of adding a whole new template, I'd rather we extract and determine if the
multipleattribute is set and just throw the wrapper in an if statement.Comment #5
grimreaperOk. Here comes the patch.
Thanks for the review.
Comment #6
jorgediazhav commentedYep. Works great.
I tested it with:
- Unlimited Selection
- Limited above +2.
- Limited selection set to 1 rolls back to the normal select.
Comment #8
markhalliwellAwesome! Thanks @Grimreaper!
Comment #9
grimreaperThanks for the commits (of other issues too) :)