Skip to content

Commit

Permalink
Merge pull request #40 from apostrophecms/feature/stepper
Browse files Browse the repository at this point in the history
Feature/stepper
  • Loading branch information
haroun authored Oct 25, 2023
2 parents 261073e + e013932 commit b71d7e4
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## UNRELEASED

### Adds

* Add group widget which is a fieldset container for other form widgets.

## 1.2.0 (2023-10-12)

### Adds
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ require('apostrophe')({
'@apostrophecms/form-checkboxes-field-widget': {},
'@apostrophecms/form-boolean-field-widget': {},
'@apostrophecms/form-conditional-widget': {},
'@apostrophecms/form-divider-widget': {}
'@apostrophecms/form-divider-widget': {},
'@apostrophecms/form-group-widget': {}
}
});
```
Expand Down Expand Up @@ -82,7 +83,7 @@ The `formWidgets` option allows us to change the widgets allowed in a form. It i
}
```

This includes the rich text widget so editors can add directions or notes in the form. The file field widget is *not included* by default since site owners should carefully consider the implications of potentially public upload access. See [the following section on file field support](#supporting-file-field-uploads-safely).
This includes the rich text widget so editors can add directions or notes in the form. The file field widget is *not included* by default since site owners should carefully consider the implications of potentially public upload access. See [the following section on file field support](#supporting-file-field-uploads-safely). The group widget is a simple fieldset container for other form field widgets and is *not included* by default either.

Any widget type can be included. A very simple form widget configuration might look like this:

Expand Down
5 changes: 5 additions & 0 deletions i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,14 @@
"formName": "Form name",
"forms": "Forms",
"globalGroup": "Form Settings",
"group": "Group",
"groupAdvanced": "Advanced",
"groupAfterSubmission": "After submission",
"groupForm": "Form",
"groupGroups": "Groups",
"groupGroupsContents": "Groups Contents",
"groupGroupsContentsHelp": "Contains all form widgets excepts groups",
"groupGroupsLabel": "Group Label",
"notFoundForm": "No matching form was found",
"queryParamKey": "Key",
"queryParamLimit": "Limit Saved Parameter Value Length (characters)",
Expand Down
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const fs = require('fs');
const path = require('path');
const connectMultiparty = require('connect-multiparty');
const fields = require('./lib/fields');
const recaptcha = require('./lib/recaptcha');
const processor = require('./lib/processor');

module.exports = {
extend: '@apostrophecms/piece-type',
Expand Down Expand Up @@ -75,8 +77,8 @@ module.exports = {
},
methods (self) {
return {
...require('./lib/recaptcha')(self),
...require('./lib/process')(self),
...recaptcha(self),
...processor(self),
async ensureCollection () {
self.db = self.apos.db.collection('aposFormSubmissions');
await self.db.ensureIndex({
Expand Down
1 change: 1 addition & 0 deletions lib/fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = {
'@apostrophecms/form-checkboxes-field': {},
'@apostrophecms/form-conditional': {},
'@apostrophecms/form-divider': {},
// '@apostrophecms/form-group': {}
'@apostrophecms/rich-text': {
toolbar: [
'styles', 'bold', 'italic', 'link',
Expand Down
File renamed without changes.
49 changes: 49 additions & 0 deletions modules/@apostrophecms/form-group-widget/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
module.exports = {
extend: '@apostrophecms/widget-type',
options: {
label: 'aposForm:group',
className: 'apos-form-group',
icon: 'file-multiple-outline-icon'
},
icons: {
'file-multiple-outline-icon': 'FileMultipleOutline'
},
fields (self) {
// Prevent nested groups
const form = self.options.apos.modules['@apostrophecms/form'];
const {
'@apostrophecms/form-group': groupWidget,
...formWidgets
} = form.fields.contents.options.widgets;

return {
add: {
groups: {
label: 'aposForm:groupGroups',
type: 'array',
required: true,
titleField: 'label',
inline: true,
fields: {
add: {
label: {
label: 'aposForm:groupGroupsLabel',
type: 'string',
required: true
},
contents: {
label: 'aposForm:groupGroupsContents',
help: 'aposForm:groupGroupsContentsHelp',
type: 'area',
contextual: false,
options: {
widgets: formWidgets
}
}
}
}
}
}
};
}
};
13 changes: 13 additions & 0 deletions modules/@apostrophecms/form-group-widget/views/widget.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% set prependIfPrefix = apos.modules['@apostrophecms/form'].prependIfPrefix %}

<div data-apos-form-groups class="apos-form-groups {{ prependIfPrefix('__groups') }}">
{% for group in data.widget.groups %}
<fieldset
class="apos-form-group {{ prependIfPrefix('__group') }}"
data-index="{{ loop.index }}"
>
<legend>{{ group.label }}</legend>
{% area group, 'contents' %}
</fieldset>
{% endfor %}
</div>
1 change: 1 addition & 0 deletions modules/@apostrophecms/form-widget/ui/src/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ $apos-form-spacing: 20px;
}

.apos-form-input,
.apos-form-group,
.apos-form-fieldset {
margin-bottom: $apos-form-spacing;
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"form builder"
],
"devDependencies": {
"apostrophe": "^3.4.0",
"apostrophe": "^3.58.1",
"eslint": "^8.50.0",
"eslint-config-apostrophe": "^4.1.0",
"eslint-config-standard": "^17.1.0",
Expand All @@ -38,4 +38,4 @@
"dependencies": {
"connect-multiparty": "^2.2.0"
}
}
}
1 change: 1 addition & 0 deletions ui/src/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ $apos-form-spacing: 35px;
}

.apos-form-input,
.apos-form-group,
.apos-form-fieldset {
.apos-modal & {
margin-bottom: $apos-form-spacing;
Expand Down

0 comments on commit b71d7e4

Please sign in to comment.