From d4fa1dd24fa8625a592f1b73c3c9ed08aa8e004d Mon Sep 17 00:00:00 2001 From: Nick Tilden Date: Wed, 21 Sep 2016 15:38:36 -0500 Subject: [PATCH 1/8] :new: Added required text to field labels --- lib/form/html.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/form/html.js b/lib/form/html.js index 55c7c51..1f2d775 100644 --- a/lib/form/html.js +++ b/lib/form/html.js @@ -169,6 +169,11 @@ const renderer = (type, errors) => { required = `required--${input.required}`; } + // Add required text to label + if (label) { + render += ``; + } + // Set opening tags based on number of inputs if (inputs > 1) { render += `
`; From ad052798209ed21f181ca83c654a2575cf7fcb62 Mon Sep 17 00:00:00 2001 From: Nick Tilden Date: Fri, 23 Sep 2016 12:57:49 -0500 Subject: [PATCH 2/8] :shirt: fixed errors and modified approach --- lib/form/html.js | 9 ++++----- tests/form.js | 13 +++++++++---- tests/html.js | 7 +++---- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/lib/form/html.js b/lib/form/html.js index 1f2d775..cc65f1a 100644 --- a/lib/form/html.js +++ b/lib/form/html.js @@ -137,6 +137,10 @@ const addRequired = (html, input, index) => { // add required to input const reName = new RegExp(`name=['"]\\s*${inp.name}\\s*['"]`); render = render.replace(reName, `name="${inp.name}" aria-required="true" required`); + + // Add required text to label + const reLabel = new RegExp(''); + render = render.replace(reLabel, `required to ${input.required}`); } }); @@ -169,11 +173,6 @@ const renderer = (type, errors) => { required = `required--${input.required}`; } - // Add required text to label - if (label) { - render += ``; - } - // Set opening tags based on number of inputs if (inputs > 1) { render += `
`; diff --git a/tests/form.js b/tests/form.js index d946a8b..f9a1355 100644 --- a/tests/form.js +++ b/tests/form.js @@ -62,6 +62,8 @@ test('Form Generation, with required attributes and inputs', t => { t.true(includes(rendered.html, 'class="required--save">Input required save', 'label gets save required classes')); t.true(includes(rendered.html, 'name="input-required-save--text" aria-required="true" required', 'input gets required--save')); + + t.true(includes(rendered.html, 'required to save', 'mark gets added after label text')); }); }); @@ -77,14 +79,16 @@ test('Form Generation, with identifier automatically required', t => { t.true(includes(rendered.html, 'class="required--save">SOme New THING', 'label gets save required classes')); t.true(includes(rendered.html, 'name="new-text-thing--text" aria-required="true" required', 'input gets required--save')); + + t.true(includes(rendered.html, 'required to save', 'mark gets added after label text')); }); }); test('Form Generation, with required, with classes on a label', t => { return types.only('baz', {}, '', config).then(rslt => { const result = rslt; - result.attributes[0].html = ''; - result.attributes[2].html = ''; + result.attributes[0].html = ''; + result.attributes[2].html = ''; return form(result); }).then(rendered => { @@ -96,13 +100,15 @@ test('Form Generation, with required, with classes on a label', t => { t.true(includes(rendered.html, 'class="I-am-a-test this-must__still_be123-here required--save">Plugin required save', 'label gets save required classes if class after for')); t.true(includes(rendered.html, 'class="I-am-a-test this-must__still_be123-here required--publish" for="', 'label gets save required classes if class before for')); + + t.true(includes(rendered.html, 'required to save', 'mark gets added after label text')); }); }); test('Form Generation, with required attributes and inputs that have wrong levels', t => { return types.only('baz', {}, '', config).then(rslt => { const result = rslt; - result.attributes[5].html = ''; + result.attributes[5].html = ''; return form(result); }).then(rendered => { @@ -174,4 +180,3 @@ test('Form Generation, with repeatables', t => { t.true(includes(rendered.html, ''), 'Indexing for input text of second instance'); }); }); - diff --git a/tests/html.js b/tests/html.js index 955e8b6..ac0d44d 100644 --- a/tests/html.js +++ b/tests/html.js @@ -10,7 +10,7 @@ test('Add Errors - Pass', t => { }, input: { description: 'I am the Bar Content Type Config textarea description', - html: '', + html: '', id: 'my-textarea', inputs: { textarea: { @@ -81,10 +81,10 @@ test('Add Errors Repeatable - Pass', t => { test('Add Required - Pass', t => { const param = { - html: '""', + html: '""', input: { description: 'I am the Bar Content Type Config textarea description', - html: '', + html: '', id: 'my-textarea', inputs: { textarea: { @@ -131,4 +131,3 @@ test('Add Required Checkbox - Pass', t => { const result = html.required(param.html, param.input, param.index); t.false(includes(result, expected)); }); - From 931b593e737dce9abb4f749ce757bdb8c946546a Mon Sep 17 00:00:00 2001 From: Nick Tilden Date: Fri, 23 Sep 2016 15:39:12 -0500 Subject: [PATCH 3/8] :shirt: inp.required fix + added test to repeatables --- lib/form/html.js | 3 ++- tests/html.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/form/html.js b/lib/form/html.js index cc65f1a..ef99ca8 100644 --- a/lib/form/html.js +++ b/lib/form/html.js @@ -90,6 +90,7 @@ const addRequired = (html, input, index) => { if (input.required === 'save' || inp.required === 'save' || input.required === 'publish' || inp.required === 'publish') { let level = ''; + const required = input.required && inp.required; if (inp.required !== undefined) { level += `required--${inp.required}`; } @@ -140,7 +141,7 @@ const addRequired = (html, input, index) => { // Add required text to label const reLabel = new RegExp(''); - render = render.replace(reLabel, `required to ${input.required}`); + render = render.replace(reLabel, `required to ${required}`); } }); diff --git a/tests/html.js b/tests/html.js index ac0d44d..bbfa1d9 100644 --- a/tests/html.js +++ b/tests/html.js @@ -41,7 +41,7 @@ test('Add Errors Repeatable - Pass', t => { }, input: { description: 'An email input with domain validation', - html: '', + html: '', id: 'my-email', inputs: [ { From 13a0dc5952d53ecc982d79b874da7f9199ab106d Mon Sep 17 00:00:00 2001 From: Nick Tilden Date: Tue, 27 Sep 2016 16:40:00 -0500 Subject: [PATCH 4/8] :new: adding in more tests --- lib/form/html.js | 2 +- tests/html.js | 62 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/lib/form/html.js b/lib/form/html.js index ef99ca8..83ff437 100644 --- a/lib/form/html.js +++ b/lib/form/html.js @@ -90,7 +90,7 @@ const addRequired = (html, input, index) => { if (input.required === 'save' || inp.required === 'save' || input.required === 'publish' || inp.required === 'publish') { let level = ''; - const required = input.required && inp.required; + const required = inp.required || input.required; if (inp.required !== undefined) { level += `required--${inp.required}`; } diff --git a/tests/html.js b/tests/html.js index bbfa1d9..f9a8a00 100644 --- a/tests/html.js +++ b/tests/html.js @@ -131,3 +131,65 @@ test('Add Required Checkbox - Pass', t => { const result = html.required(param.html, param.input, param.index); t.false(includes(result, expected)); }); + +test('Add Required and Repeatable - Pass', t => { + const param = { + html: '"
"', + input: { + description: 'I am the Bar Content Type Config text description', + html: '
', + id: 'text-required', + inputs: { + text: { + id: '91f79620-ba21-4a4a-a4c7-02f456129b0f--1', + label: 'Add Your Text', + name: 'name--text', + placeholder: 'Text goes here', + type: 'text', + }, + }, + name: 'Add Your Text', + required: 'publish', + repeatable: 'true', + type: 'text', + }, + index: undefined, + }; + const expected = 'aria-required="true" required'; + const result = html.required(param.html, param.input, param.index); + t.false(includes(result, expected)); +}); + +test('Add Object Required - Pass', t => { + const param = { + html: '""', + input: { + name: 'Object', + description: 'I am the Foo Object text description', + html: '
{{input.name}}

{{input.description}}

', + id: 'object-required', + inputs: { + text: { + id: '91f79620-ba21-4a4a-a4c7-02f456129b0f--1', + label: 'Add Your Text', + name: 'name--text', + placeholder: 'Text goes here', + type: 'text', + required: 'publish', + }, + url: { + id: '91f79620-ba21-4a4a-a4c7-02f456129b0f--2', + label: 'Add Your URL', + name: 'name--url', + placeholder: 'http://', + type: 'url', + required: 'publish', + }, + }, + }, + index: undefined, + }; + const expected = 'aria-required="true" required'; + const result = html.required(param.html, param.input, param.index); + t.false(includes(result, expected)); +}); From 98d49f9d0e414a4019e6c97252db2aab71454472 Mon Sep 17 00:00:00 2001 From: Nick Tilden Date: Wed, 28 Sep 2016 10:24:09 -0500 Subject: [PATCH 5/8] :new: replaced required condional statement --- lib/form/html.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/lib/form/html.js b/lib/form/html.js index 83ff437..b8f2840 100644 --- a/lib/form/html.js +++ b/lib/form/html.js @@ -89,14 +89,8 @@ const addRequired = (html, input, index) => { } if (input.required === 'save' || inp.required === 'save' || input.required === 'publish' || inp.required === 'publish') { - let level = ''; const required = inp.required || input.required; - if (inp.required !== undefined) { - level += `required--${inp.required}`; - } - else { - level += `required--${input.required}`; - } + const level = `required--${required}`; // pre-regex strings const stringClass = 'class=["\'][\\w\\W\\s]+?["\']'; From 1b45e605f8a7ef2c354b516161a44340f99c1b3f Mon Sep 17 00:00:00 2001 From: Nick Tilden Date: Thu, 29 Sep 2016 09:42:02 -0500 Subject: [PATCH 6/8] :new: moved requied class to mark only --- lib/form/html.js | 10 +++------- tests/form.js | 23 ++++++++--------------- tests/html.js | 16 ++++++++-------- 3 files changed, 19 insertions(+), 30 deletions(-) diff --git a/lib/form/html.js b/lib/form/html.js index b8f2840..411058a 100644 --- a/lib/form/html.js +++ b/lib/form/html.js @@ -135,7 +135,7 @@ const addRequired = (html, input, index) => { // Add required text to label const reLabel = new RegExp(''); - render = render.replace(reLabel, `required to ${required}`); + render = render.replace(reLabel, `required to ${required}`); } }); @@ -163,14 +163,10 @@ const renderer = (type, errors) => { const context = input.inputs; let html = nunjucks.renderString(input.html, context); let render = ''; - let required = ''; - if (input.hasOwnProperty('required')) { - required = `required--${input.required}`; - } // Set opening tags based on number of inputs if (inputs > 1) { - render += `
`; + render += `
`; render += `${input.name}`; // Add Description @@ -179,7 +175,7 @@ const renderer = (type, errors) => { } } else { - render += `
`; + render += `
`; } // Wraps repeatable attributes around div diff --git a/tests/form.js b/tests/form.js index f9a1355..4c918da 100644 --- a/tests/form.js +++ b/tests/form.js @@ -60,10 +60,8 @@ test('Form Generation, with required attributes and inputs', t => { t.is(typeof rendered.scripts, 'string', 'Scripts is a string'); t.is(typeof rendered.html, 'string', 'HTML is a string'); - t.true(includes(rendered.html, 'class="required--save">Input required save', 'label gets save required classes')); t.true(includes(rendered.html, 'name="input-required-save--text" aria-required="true" required', 'input gets required--save')); - - t.true(includes(rendered.html, 'required to save', 'mark gets added after label text')); + t.true(includes(rendered.html, 'required to save', 'mark gets added after label text')); }); }); @@ -77,18 +75,16 @@ test('Form Generation, with identifier automatically required', t => { t.is(typeof rendered.scripts, 'string', 'Scripts is a string'); t.is(typeof rendered.html, 'string', 'HTML is a string'); - t.true(includes(rendered.html, 'class="required--save">SOme New THING', 'label gets save required classes')); t.true(includes(rendered.html, 'name="new-text-thing--text" aria-required="true" required', 'input gets required--save')); - - t.true(includes(rendered.html, 'required to save', 'mark gets added after label text')); + t.true(includes(rendered.html, 'required to save', 'mark gets added after label text')); }); }); test('Form Generation, with required, with classes on a label', t => { return types.only('baz', {}, '', config).then(rslt => { const result = rslt; - result.attributes[0].html = ''; - result.attributes[2].html = ''; + result.attributes[0].html = ''; + result.attributes[2].html = ''; return form(result); }).then(rendered => { @@ -98,17 +94,14 @@ test('Form Generation, with required, with classes on a label', t => { t.is(typeof rendered.scripts, 'string', 'Scripts is a string'); t.is(typeof rendered.html, 'string', 'HTML is a string'); - t.true(includes(rendered.html, 'class="I-am-a-test this-must__still_be123-here required--save">Plugin required save', 'label gets save required classes if class after for')); - t.true(includes(rendered.html, 'class="I-am-a-test this-must__still_be123-here required--publish" for="', 'label gets save required classes if class before for')); - - t.true(includes(rendered.html, 'required to save', 'mark gets added after label text')); + t.true(includes(rendered.html, 'required to save', 'mark gets added after label text')); }); }); test('Form Generation, with required attributes and inputs that have wrong levels', t => { return types.only('baz', {}, '', config).then(rslt => { const result = rslt; - result.attributes[5].html = ''; + result.attributes[5].html = ''; return form(result); }).then(rendered => { @@ -121,8 +114,8 @@ test('Form Generation, required knows publish vs save', t => { return types.only('baz', {}, '', config).then(result => { return form(result); }).then(rendered => { - t.true(includes(rendered.html, '
', 'determines save for plugin')); - t.true(includes(rendered.html, '
', 'determines publish for plugin')); + t.true(includes(rendered.html, 'required to save', 'determines save for plugin')); + t.true(includes(rendered.html, 'required to publish', 'determines publish for plugin')); }); }); diff --git a/tests/html.js b/tests/html.js index f9a8a00..e52937c 100644 --- a/tests/html.js +++ b/tests/html.js @@ -10,7 +10,7 @@ test('Add Errors - Pass', t => { }, input: { description: 'I am the Bar Content Type Config textarea description', - html: '', + html: '', id: 'my-textarea', inputs: { textarea: { @@ -41,7 +41,7 @@ test('Add Errors Repeatable - Pass', t => { }, input: { description: 'An email input with domain validation', - html: '', + html: '', id: 'my-email', inputs: [ { @@ -81,10 +81,10 @@ test('Add Errors Repeatable - Pass', t => { test('Add Required - Pass', t => { const param = { - html: '""', + html: '""', input: { description: 'I am the Bar Content Type Config textarea description', - html: '', + html: '', id: 'my-textarea', inputs: { textarea: { @@ -134,10 +134,10 @@ test('Add Required Checkbox - Pass', t => { test('Add Required and Repeatable - Pass', t => { const param = { - html: '"
"', + html: '"
"', input: { description: 'I am the Bar Content Type Config text description', - html: '
', + html: '
', id: 'text-required', inputs: { text: { @@ -162,11 +162,11 @@ test('Add Required and Repeatable - Pass', t => { test('Add Object Required - Pass', t => { const param = { - html: '""', + html: '""', input: { name: 'Object', description: 'I am the Foo Object text description', - html: '
{{input.name}}

{{input.description}}

', + html: '
{{input.name}}

{{input.description}}

', id: 'object-required', inputs: { text: { From 4fb199275df558fd39d20ab79264edbfac00ca9f Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Mon, 10 Oct 2016 14:37:59 -0400 Subject: [PATCH 7/8] chore(package): update input-plugin-quote to version 0.2.1 https://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c57727a..fabe358 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "input-plugin-checkbox": "^0.3.1", "input-plugin-datetime": "^0.2.2", "input-plugin-email": "^0.2.0", - "input-plugin-quote": "0.0.1", + "input-plugin-quote": "0.2.1", "input-plugin-select": "^0.3.0", "input-plugin-selects-related": "0.1.3", "input-plugin-text": "^0.1.0", From 345194a2f57b74cecd656755d9ea71e7b7bb4254 Mon Sep 17 00:00:00 2001 From: greenkeeperio-bot Date: Mon, 10 Oct 2016 16:48:15 -0400 Subject: [PATCH 8/8] chore(package): update deepmerge to version 1.1.0 https://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index fabe358..edb11c1 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "license": "Apache-2.0", "dependencies": { "browserify": "^13.0.1", - "deepmerge": "^0.2.10", + "deepmerge": "^1.1.0", "js-yaml": "^3.5.3", "lodash": "^4.14.1", "node-dir": "^0.1.11",