diff --git a/lib/content-types/only.js b/lib/content-types/only.js
index f16b860..153fb34 100644
--- a/lib/content-types/only.js
+++ b/lib/content-types/only.js
@@ -3,9 +3,10 @@
const merge = require('deepmerge');
const utils = require('../utils');
-const only = (type, config) => {
+const only = (type, configuration) => {
return new Promise((resolve) => {
const mergedType = type;
+ const config = configuration;
const configured = Object.keys(config);
const attrs = mergedType.attributes.map(attribute => {
const attr = attribute;
@@ -23,6 +24,11 @@ const only = (type, config) => {
return attr;
}
+ // check if repeatable but not an array
+ if (attr.hasOwnProperty('repeatable') && typeof attr.repeatable === 'object' && !Array.isArray(config[attr.id])) {
+ config[attr.id] = [config[attr.id]];
+ }
+
// Flattens multiple instances and updates ids and names
if (Array.isArray(config[attr.id])) {
attr.inputs = config[attr.id].map((data, index) => {
diff --git a/lib/form/html.js b/lib/form/html.js
index bd0e214..55c7c51 100644
--- a/lib/form/html.js
+++ b/lib/form/html.js
@@ -107,6 +107,11 @@ const addRequired = (html, input, index) => {
// THIS input's label
const label = render.match(regexLabel);
+ // checks if label is not found
+ if (label === null || !Array.isArray(label) || label.length < 2) {
+ return;
+ }
+
// regex to get first class attributes from the captured label
const regexClass = new RegExp(`.*(${stringClass})`);
diff --git a/lib/utils.js b/lib/utils.js
index c1df878..f15ede4 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -37,7 +37,7 @@ exports.singleItem = (key, value, arr) => {
};
/**
- * Pop the last element after splitting the string
+ * Pop the last element if length > 1 after splitting the string
*
* @param {string} input - Input string to be split
* @param {string} splitter - string to split against
@@ -46,7 +46,9 @@ exports.singleItem = (key, value, arr) => {
*/
exports.splitPop = (input, splitter) => {
let blocks = input.split(splitter);
- blocks.pop();
+ if (blocks.length > 1) {
+ blocks.pop();
+ }
blocks = blocks.join(splitter);
return blocks;
diff --git a/tests/content-types.js b/tests/content-types.js
index c63f5b4..5e0654e 100644
--- a/tests/content-types.js
+++ b/tests/content-types.js
@@ -69,6 +69,9 @@ test('Content Types', t => {
source: { value: 'baz2' },
},
],
+ 'something-new-other': {
+ text: { value: 'bar' },
+ },
}).then(result => {
t.deepEqual(result, barExpected, 'Only method works!');
t.pass();
diff --git a/tests/fixtures/objects/bar-expected.js b/tests/fixtures/objects/bar-expected.js
index e52ea26..65e2082 100644
--- a/tests/fixtures/objects/bar-expected.js
+++ b/tests/fixtures/objects/bar-expected.js
@@ -184,6 +184,37 @@ const barExpected = {
type: 'quote',
validation: 'validation',
},
+ {
+ description: 'I am the Bar Content Type Config text field repeatable',
+ html: '',
+ id: 'something-new',
+ repeatable: {
+ min: 1,
+ max: 9007199254740991,
+ },
+ inputs: [
+ {
+ text: {
+ id: '5ba58361-87b7-4e79-8ea0-e54635ad23bb--0',
+ label: 'SOme New THING',
+ name: 'something-new--text--0',
+ placeholder: 'Text Goes Here',
+ settings: {
+ empty: true,
+ },
+ type: 'text',
+ validation: {
+ function: 'textValidation',
+ on: 'blur',
+ },
+ value: 'foo',
+ },
+ },
+ ],
+ name: 'SOme New THING',
+ type: 'text',
+ validation: 'validation',
+ },
],
};
diff --git a/tests/fixtures/objects/bar-input.js b/tests/fixtures/objects/bar-input.js
index dfb2a3e..2e8d01d 100644
--- a/tests/fixtures/objects/bar-input.js
+++ b/tests/fixtures/objects/bar-input.js
@@ -88,6 +88,36 @@ const barInput = {
type: 'quote',
validation: 'validation',
},
+ {
+ description: 'I am the Bar Content Type Config text field repeatable',
+ html: '',
+ id: 'something-new',
+ repeatable: {
+ min: 1,
+ max: 9007199254740991,
+ },
+ inputs: [
+ {
+ text: {
+ id: '5ba58361-87b7-4e79-8ea0-e54635ad23bb--0',
+ label: 'SOme New THING',
+ name: 'something-new--text--0',
+ placeholder: 'Text Goes Here',
+ settings: {
+ empty: true,
+ },
+ type: 'text',
+ validation: {
+ function: 'textValidation',
+ on: 'blur',
+ },
+ },
+ },
+ ],
+ name: 'SOme New THING',
+ type: 'text',
+ validation: 'validation',
+ },
],
};