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: {