Skip to content

Commit

Permalink
Merge pull request #88 from ayush2k/bugfix/checkbox-required
Browse files Browse the repository at this point in the history
 add check to skip checkbox in required
  • Loading branch information
scottnath authored Aug 11, 2016
2 parents 5a20ef5 + 41c2307 commit dce4d7d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/form/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const addRequired = (html, input, index) => {
required: input.inputs[index][inp].required,
name: `${input.id}--${inp}--${index}`,
id: input.inputs[index][inp].id,
type: input.inputs[index][inp].type,
});
});
}
Expand All @@ -76,11 +77,17 @@ const addRequired = (html, input, index) => {
required: input.inputs[inp].required,
name: `${input.id}--${inp}`,
id: input.inputs[inp].id,
type: input.inputs[inp].type,
});
});
}

inputs.map(inp => {
// Skip the required attribute for checkbox and radio on browser
if (input.type === 'checkbox' || input.type === 'radio') {
return;
}

if (input.required === 'save' || inp.required === 'save' || input.required === 'publish' || inp.required === 'publish') {
let level = '';
if (inp.required !== undefined) {
Expand Down
26 changes: 26 additions & 0 deletions tests/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,29 @@ test('Add Required - Pass', t => {
t.true(includes(result, expected));
});

test('Add Required Checkbox - Pass', t => {
const param = {
html: '"<label for="91f79620-ba21-4a4a-a4c7-02f456129b0f">My Awesome Text Area</label><textarea id="91f79620-ba21-4a4a-a4c7-02f456129b0f" name="my-textarea--textarea" placeholder="Type something..." />test</textarea>"',
input: {
description: 'I am the Bar Content Type Config textarea description',
html: '"<label for="91f79620-ba21-4a4a-a4c7-02f456129b0f--1"><input type="checkbox" name="my-checkbox--checkbox" id="91f79620-ba21-4a4a-a4c7-02f456129b0f--1" value="one" >One</label>"',
id: 'my-checkbox',
inputs: {
checkbox: {
id: '91f79620-ba21-4a4a-a4c7-02f456129b0f--1',
label: 'My Awesome Checkbox',
name: 'my-checkbox--checkbox',
type: 'checkbox',
},
},
name: 'My Awesome Checkbox',
required: 'save',
type: 'checkbox',
},
index: undefined,
};
const expected = 'aria-required="true" required';
const result = html.required(param.html, param.input, param.index);
t.false(includes(result, expected));
});

0 comments on commit dce4d7d

Please sign in to comment.