From 3d5f4ee971766bda9c9a59d441b19f5f406006da Mon Sep 17 00:00:00 2001 From: Ayush Gupta Date: Thu, 11 Aug 2016 12:09:22 -0400 Subject: [PATCH 1/2] :bug: add check to skip checkbox in required --- lib/form/html.js | 5 +++++ tests/html.js | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/lib/form/html.js b/lib/form/html.js index 5d9b700..e2d6212 100644 --- a/lib/form/html.js +++ b/lib/form/html.js @@ -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, }); }); } @@ -76,11 +77,15 @@ 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 => { + 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) { diff --git a/tests/html.js b/tests/html.js index 6710545..955e8b6 100644 --- a/tests/html.js +++ b/tests/html.js @@ -106,3 +106,29 @@ test('Add Required - Pass', t => { t.true(includes(result, expected)); }); +test('Add Required Checkbox - Pass', t => { + const param = { + html: '""', + input: { + description: 'I am the Bar Content Type Config textarea description', + html: '""', + 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)); +}); + From 41c23073a0fb08c6f455629d70797e3c8527d860 Mon Sep 17 00:00:00 2001 From: Ayush Gupta Date: Thu, 11 Aug 2016 13:22:30 -0400 Subject: [PATCH 2/2] :art: add space between condition --- lib/form/html.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/form/html.js b/lib/form/html.js index e2d6212..92c23b6 100644 --- a/lib/form/html.js +++ b/lib/form/html.js @@ -83,9 +83,11 @@ const addRequired = (html, input, index) => { } 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) {