Skip to content

Commit

Permalink
Feature/add select support (#123)
Browse files Browse the repository at this point in the history
* Add select form element to use inside statement generator

* Refactor _getGroupValue to evaluate isText as not radio or checkbox

* Update README with form element support content
  • Loading branch information
rvantonisse committed Mar 28, 2019
1 parent 3f9caec commit 5f65831
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,20 @@ The generator tool is setup in such a way that content is seperated from functio

The create statement contents are wrapped inside `<section class="page create">`. Just simply add or remove the html markup to edit the form.

Supported form elements are:
- input

NOTE: Input types of type radio and checkbox require the value attribute set, for example:

```html
<input type="radio" name="radiogroup" value="option 1">
<input type="radio" name="radiogroup" value="option 2">
<input type="radio" name="radiogroup" value="option x">
```

- textarea
- select

There is one extra functionality available to dynamically add extra line to grouped form input; add-line. To use this there are several practical examples inside the form. Required for add-line to work is this basic setup:

```html
Expand Down
6 changes: 4 additions & 2 deletions content-images/wai-statements/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
var nodeName = item.nodeName;
var isProto = item.parentNode && item.parentNode.classList.contains('proto');

if (['INPUT', 'TEXTAREA'].indexOf(nodeName) !== -1 && !isProto) {
if (['INPUT', 'TEXTAREA', 'SELECT'].indexOf(nodeName) !== -1 && !isProto) {
_setFormData(item);
}
});
Expand Down Expand Up @@ -103,7 +103,8 @@
function _getGroupValue(groupName) {
var group = _getFormGroup(groupName) || [];
var checkedMembers = Array.prototype.filter.call(group, function getChecked(member) {
var isText = member.type === 'text';
var isText = member.type !== 'radio'
|| member.type !== 'checkbox';

return member.checked || (isText && member.value);
});
Expand Down Expand Up @@ -177,6 +178,7 @@
var allowedInputs = [
'INPUT',
'TEXTAREA',
'SELECT'
];

// Store formdata for changed input
Expand Down

0 comments on commit 5f65831

Please sign in to comment.