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

Feature/select multiple #43

Merged
merged 6 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
30 changes: 30 additions & 0 deletions modules/@apostrophecms/form-select-field-widget/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ module.exports = {
}
}
}
},
allowMultiple: {
label: 'aposForm:selectAllowMultiple',
type: 'boolean',
def: false
},
size: {
label: 'aposForm:selectSize',
type: 'integer',
def: 0,
min: 0,
if: {
allowMultiple: true
}
}
}
},
Expand All @@ -38,5 +52,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 ?? false,
size: widget.size ?? 0
},
options,
_with
);
}
};
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<select
class="apos-form-input {{ prependIfPrefix('__input') }}" id="{{ id }}"
name="{{ widget.fieldName}}" {% if widget.required %}required{% endif %}
{% if widget.allowMultiple %}multiple {% if widget.size %}size="{{ widget.size }}"{% endif %}{% endif %}
>
<option value="">{{ __t("aposForm:selectBlank") }}</option>
{% for choice in widget.choices %}
Expand Down