Skip to content

Commit c7ef469

Browse files
committed
refactor(InputEditor): Better handling of empty values - add innerClass and wrapperClass to Style section
1 parent 1c34a31 commit c7ef469

File tree

2 files changed

+35
-34
lines changed

2 files changed

+35
-34
lines changed

src/composables/useInputEditor.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,39 @@ export function useInputEditor() {
2929

3030
const defaultObject = { readonly: readonlyValue, disabled: disabledValue, preserve: preserveValue }
3131

32+
// outer class
3233
let outerClass: string | undefined = ''
33-
if (data.outerClassGrid && data.outerClassGrid !== 'col-12')
34-
outerClass = data.outerClassGrid
3534
if (data.outerClass)
36-
outerClass = `${outerClass} ${data.outerClass}`
35+
outerClass = `${outerClass} ${data.outerClass}`.trim()
3736

38-
if (outerClass.trim().length === 0)
39-
outerClass = undefined
37+
// wrapper class
38+
let wrapperClass: string | undefined = ''
39+
if (data.wrapperClass)
40+
wrapperClass = `${wrapperClass} ${data.wrapperClass}`.trim()
4041

41-
const undefinedObject = { prime: undefined, schemaResultFormKey: undefined, _dollar_formkit: undefined, slots: undefined, selectButton: undefined, outerClassGrid: undefined }
42+
// inner class
43+
let innerClass: string | undefined = ''
44+
if (data.innerClass)
45+
innerClass = `${innerClass} ${data.innerClass}`.trim()
46+
47+
const undefinedObject = { prime: undefined, schemaResultFormKey: undefined, _dollar_formkit: undefined, slots: undefined, selectButton: undefined }
4248

4349
const useOptions = primeInputWithOptionNames.map(s => `prime${s}`).includes(formkitInput)
4450

4551
let result = {}
4652
if (useOptions)
47-
result = { ...data, $formkit: formkitInput, ...tempData, ...undefinedObject, ...defaultObject, outerClass, optionLabel: 'label', optionValue: 'value' }
53+
result = { ...data, $formkit: formkitInput, ...tempData, ...undefinedObject, ...defaultObject, outerClass, wrapperClass, innerClass, optionLabel: 'label', optionValue: 'value' }
4854
else
49-
result = { ...data, $formkit: formkitInput, ...tempData, ...undefinedObject, ...defaultObject, outerClass, options: undefined }
55+
result = { ...data, $formkit: formkitInput, ...tempData, ...undefinedObject, ...defaultObject, outerClass, wrapperClass, innerClass, options: undefined }
56+
57+
// cleanup empty values
58+
for (const key in result) {
59+
const value = result[key]
60+
if ((typeof value === 'string' || value instanceof String)) {
61+
if (value.trim().length === 0)
62+
result[key] = undefined
63+
}
64+
}
5065

5166
return result
5267
}

src/composables/useInputEditorSchema.ts

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,6 @@ export function useInputEditorSchema() {
2929
{ label: 'Submit', value: 'submit' },
3030
]
3131

32-
const colOptions = [
33-
{ label: 'Col-1', value: 'col-1' },
34-
{ label: 'Col-2', value: 'col-2' },
35-
{ label: 'Col-3', value: 'col-3' },
36-
{ label: 'Col-4', value: 'col-4' },
37-
{ label: 'Col-5', value: 'col-5' },
38-
{ label: 'Col-6', value: 'col-6' },
39-
{ label: 'Col-7', value: 'col-7' },
40-
{ label: 'Col-8', value: 'col-8' },
41-
{ label: 'Col-9', value: 'col-9' },
42-
{ label: 'Col-10', value: 'col-10' },
43-
{ label: 'Col-11', value: 'col-11' },
44-
{ label: 'Col-12', value: 'col-12' },
45-
]
46-
4732
function editorSchema(inputOptions: any[] = primeInputOptions([...primeInputNames, ...primeOutputNames])) {
4833
return [
4934
{
@@ -242,20 +227,22 @@ export function useInputEditorSchema() {
242227
name: 'outerClass',
243228
label: 'Outer Class',
244229
key: 'schema_outerClass',
245-
outerClass: 'col-6',
246230
preserve: true,
247231
},
248232
{
249-
$formkit: 'primeSelect',
233+
$formkit: 'primeInputText',
250234
if: '$get(selectButton).value === \'showStyle\'',
251-
name: 'outerClassGrid',
252-
value: 'col-12',
253-
label: 'Grid Options',
254-
optionLabel: 'label',
255-
optionValue: 'value',
256-
options: colOptions,
257-
key: 'schema_outer-class-grid',
258-
outerClass: 'col-6',
235+
name: 'wrapperClass',
236+
label: 'Wrapper Class',
237+
key: 'schema_wrapperClass',
238+
preserve: true,
239+
},
240+
{
241+
$formkit: 'primeInputText',
242+
if: '$get(selectButton).value === \'showStyle\'',
243+
name: 'innerClass',
244+
label: 'Inner Class',
245+
key: 'schema_innerClass',
259246
preserve: true,
260247
},
261248
{
@@ -272,7 +259,6 @@ export function useInputEditorSchema() {
272259
if: '$get(selectButton).value === \'showValidation\'',
273260
name: 'validation-visibility',
274261
label: 'Field Validation Visibility',
275-
value: 'blur',
276262
optionLabel: 'label',
277263
optionValue: 'value',
278264
options: validationOptions,

0 commit comments

Comments
 (0)