From beb7fc4504bbca4ef9fcb7883fb00b84f1e332b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Harouna=20Traor=C3=A9?= Date: Fri, 27 Oct 2023 17:18:07 +0200 Subject: [PATCH 1/5] add multiple and size fields to select widget --- CHANGELOG.md | 1 + i18n/en.json | 2 ++ .../form-select-field-widget/index.js | 29 +++++++++++++++++++ .../views/widget.html | 1 + 4 files changed, 33 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 131383c..30ca4ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Adds * Add group widget which is a fieldset container for other form widgets. +* Add multiple and size fields to select widget. ### Fixes diff --git a/i18n/en.json b/i18n/en.json index 1a1b6e6..a8a5249 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -84,8 +84,10 @@ "recaptchaValidationError": "There was a problem validating your reCAPTCHA verification submission.", "requiredError": "This field is required", "select": "Select input", + "selectAllowMultiple": "Allow multiple options to be selected", "selectBlank": "", "selectChoice": "Select input options", + "selectSize": "Number of options in the list that should be visible", "submitLabel": "Submit button label", "templateOptional": "(Optional)", "text": "Text input", diff --git a/modules/@apostrophecms/form-select-field-widget/index.js b/modules/@apostrophecms/form-select-field-widget/index.js index c6e5c46..06ac765 100644 --- a/modules/@apostrophecms/form-select-field-widget/index.js +++ b/modules/@apostrophecms/form-select-field-widget/index.js @@ -26,6 +26,19 @@ module.exports = { } } } + }, + allowMultiple: { + label: 'aposForm:selectAllowMultiple', + type: 'boolean', + def: true + }, + size: { + label: 'aposForm:selectSize', + type: 'number', + def: 0, + if: { + allowMultiple: true + } } } }, @@ -38,5 +51,21 @@ module.exports = { output[widget.fieldName] = self.apos.launder.select(input[widget.fieldName], choices); } }; + }, + extendMethods (self) { + return { + async output(_super, req, widget, options, _with) { + return _super( + req, + { + ...widget, + allowMultiple: widget.allowMultiple ?? true, + size: widget.size ?? 0 + }, + options, + _with + ); + } + }; } }; diff --git a/modules/@apostrophecms/form-select-field-widget/views/widget.html b/modules/@apostrophecms/form-select-field-widget/views/widget.html index 1c58568..30d9c58 100644 --- a/modules/@apostrophecms/form-select-field-widget/views/widget.html +++ b/modules/@apostrophecms/form-select-field-widget/views/widget.html @@ -17,6 +17,7 @@