Skip to content

Commit

Permalink
Merge pull request #39 from punchcard-cms/bug-fix/options-override
Browse files Browse the repository at this point in the history
Bug fix/options override
  • Loading branch information
scottnath authored Jun 28, 2016
2 parents 520078e + a8ef535 commit d6e0a3e
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/content-types/merge.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ const squish = (types) => {
merged.validation = plugin.inputs[attr].validation;
merged.type = plugin.inputs[attr].type;

// Options of attribute overrides default
if (attribute.inputs[attr].hasOwnProperty('options')) {
merged.options = attribute.inputs[attr].options;
}

// add required if it doesn't exist
if (!merged.hasOwnProperty('required')) {
merged.required = plugin.required;
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"eslint-config-punchcard": "^1.0.0",
"ghooks": "^1.2.4",
"input-plugin-datetime": "^0.0.1",
"input-plugin-select": "^0.1.0",
"input-plugin-email": "^0.1.0",
"input-plugin-quote": "0.0.1",
"input-plugin-text": "^0.0.5",
Expand Down
13 changes: 13 additions & 0 deletions tests/fixtures/content-types/baz.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,16 @@ attributes:
required: 'publish'
settings:
empty: false
- type: select
name: example dropdown
id: example-dropdown
inputs:
select:
label: Example Dropdown
options:
- label: Option 1
value: option1
- label: Option 2
value: option2
settings:
multiple: false
15 changes: 15 additions & 0 deletions tests/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,18 @@ test('Form Generation, with errors', t => {
t.true(includes(rendered.html, 'name="email-field--email" aria-invalid="true"', 'error adds aria-invalid'));
});
});

test('Form Generation, overrides options in select', t => {
return types.only('baz').then(result => {
return form(result);
}).then(rendered => {
t.true(includes(rendered.html, '<option value="option1" >Option 1</option>', 'determines existence of option1'));
t.true(includes(rendered.html, '<option value="option2" >Option 2</option>', 'determines existence of option2'));
t.false(includes(rendered.html, '<option value="mike" >Michaelangelo</option>', 'determines non-existence of default option 1'));
t.false(includes(rendered.html, '<option value="leo" >Leonardo</option>', 'determines non-existence of default option 2'));
t.false(includes(rendered.html, '<option value="ralph" >Raphael</option>', 'determines non-existence of default option 3'));
t.false(includes(rendered.html, '<option value="don" >Donatello</option>', 'determines non-existence of default option 4'));
});
});


1 change: 0 additions & 1 deletion tests/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ test('Validate - Pass', t => {
};

const result = validation(input, ct);

t.true(result, 'All validation passes');
});
});
Expand Down

0 comments on commit d6e0a3e

Please sign in to comment.