diff --git a/lib/form/html.js b/lib/form/html.js index aec5593..31bbaab 100644 --- a/lib/form/html.js +++ b/lib/form/html.js @@ -93,7 +93,6 @@ const addRequired = (html, input, index) => { const level = `required--${required}`; // pre-regex strings - const stringClass = 'class=["\'][\\w\\W\\s]+?["\']'; const stringFor = `for=["']\\s*${inp.id}\\s*["']`; // regex to get the label for THIS input @@ -107,27 +106,9 @@ const addRequired = (html, input, index) => { return; } - // regex to get first class attributes from the captured label - const regexClass = new RegExp(`.*(${stringClass})`); - - // regex to get classes out of `class` - const regexClasses = new RegExp('class=["\']([\\w\\s\\W]+?)["\']'); - // regex to search for `for` const reFor = new RegExp(`(${stringFor})`); - - // first, check if `class` exists in label - if (Array.isArray(label[1].match(regexClass))) { - const cls = label[1].match(regexClass); - const classAttr = cls[1].match(regexClasses); - const classes = classAttr[1].split(/\s+/).concat([level]); - const newClass = `class="${classes.join(' ')}"`; - render = render.replace(label[0], label[0].replace(classAttr[0], newClass)); - } - else { - // else, we add class after the `for` attribute - render = render.replace(reFor, `for="${inp.id}" class="${level}"`); - } + render = render.replace(reFor, `for="${inp.id}"`); // add required to input const reName = new RegExp(`name=['"]\\s*${inp.name}\\s*['"]`); @@ -135,7 +116,8 @@ 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, `\u00a0required to ${required}`); + render += ''; } }); diff --git a/tests/html.js b/tests/html.js index e52937c..493bbcd 100644 --- a/tests/html.js +++ b/tests/html.js @@ -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: '', + html: '', id: 'object-required', inputs: { text: {