@record-evolution/widget-form 1.0.25 → 1.0.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/widget-form.d.ts +2 -0
- package/dist/widget-form.js +153 -138
- package/dist/widget-form.js.map +1 -1
- package/package.json +1 -1
- package/src/definition-schema.d.ts +24 -0
- package/src/definition-schema.json +53 -5
- package/src/widget-form.ts +37 -7
package/src/widget-form.ts
CHANGED
|
@@ -117,12 +117,13 @@ export class WidgetForm extends LitElement {
|
|
|
117
117
|
let rawValue: any
|
|
118
118
|
|
|
119
119
|
if (field.hiddenField) {
|
|
120
|
-
rawValue = field
|
|
120
|
+
rawValue = this.effectivePreFilledValue(field) ?? this.effectiveDefaultValue(field) ?? ''
|
|
121
121
|
} else if (field.type === 'checkbox') {
|
|
122
122
|
rawValue = formData.has(name) ? 'on' : 'off'
|
|
123
123
|
} else {
|
|
124
124
|
const entry = formData.get(name)
|
|
125
|
-
rawValue =
|
|
125
|
+
rawValue =
|
|
126
|
+
entry === null || entry === '' ? (this.effectiveDefaultValue(field) ?? '') : entry
|
|
126
127
|
}
|
|
127
128
|
|
|
128
129
|
return {
|
|
@@ -169,6 +170,31 @@ export class WidgetForm extends LitElement {
|
|
|
169
170
|
this.dialogOpen = false
|
|
170
171
|
}
|
|
171
172
|
|
|
173
|
+
// preFilledValue/defaultValue and their *Multiline/*Boolean twins are separate
|
|
174
|
+
// config keys (the editor shows a single-line, multi-line or checkbox input
|
|
175
|
+
// depending on the field type). Resolve by the current type — normalizing the
|
|
176
|
+
// boolean keys to 'true'/'false' strings for the existing downstream logic —
|
|
177
|
+
// and fall back to the single-line key so fields configured before the split
|
|
178
|
+
// keep their values. A value lingering in a hidden twin key after a type
|
|
179
|
+
// switch is ignored.
|
|
180
|
+
effectivePreFilledValue(field: Column): string | undefined {
|
|
181
|
+
if (field.type === 'textarea')
|
|
182
|
+
return (field.preFilledValueMultiline as string | undefined) ?? field.preFilledValue
|
|
183
|
+
if (field.type === 'checkbox')
|
|
184
|
+
return field.preFilledValueBoolean != null
|
|
185
|
+
? String(field.preFilledValueBoolean)
|
|
186
|
+
: field.preFilledValue
|
|
187
|
+
return field.preFilledValue
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
effectiveDefaultValue(field: Column): string | undefined {
|
|
191
|
+
if (field.type === 'textarea')
|
|
192
|
+
return (field.defaultValueMultiline as string | undefined) ?? field.defaultValue
|
|
193
|
+
if (field.type === 'checkbox')
|
|
194
|
+
return field.defaultValueBoolean != null ? String(field.defaultValueBoolean) : field.defaultValue
|
|
195
|
+
return field.defaultValue
|
|
196
|
+
}
|
|
197
|
+
|
|
172
198
|
formatValue(value: string, type: string): any {
|
|
173
199
|
switch (type) {
|
|
174
200
|
case 'numberfield': {
|
|
@@ -218,14 +244,16 @@ export class WidgetForm extends LitElement {
|
|
|
218
244
|
}
|
|
219
245
|
|
|
220
246
|
renderCheckbox(field: Column, i: number) {
|
|
247
|
+
const preFilledValue = this.effectivePreFilledValue(field)
|
|
248
|
+
const defaultValue = this.effectiveDefaultValue(field)
|
|
221
249
|
return html`
|
|
222
250
|
<div class="checkbox-container">
|
|
223
251
|
<md-checkbox
|
|
224
252
|
name="column-${i}"
|
|
225
253
|
aria-label=${field.label ?? ''}
|
|
226
|
-
?checked=${String(
|
|
254
|
+
?checked=${String(preFilledValue ?? defaultValue) === 'true'}
|
|
227
255
|
supporting-text=${field.description ?? ''}
|
|
228
|
-
?required=${field.required && !
|
|
256
|
+
?required=${field.required && !defaultValue && !preFilledValue}
|
|
229
257
|
></md-checkbox>
|
|
230
258
|
<label class="label"> ${field.label} </label>
|
|
231
259
|
</div>
|
|
@@ -233,15 +261,17 @@ export class WidgetForm extends LitElement {
|
|
|
233
261
|
}
|
|
234
262
|
|
|
235
263
|
renderTextArea(field: Column, i: number) {
|
|
264
|
+
const preFilledValue = this.effectivePreFilledValue(field)
|
|
265
|
+
const defaultValue = this.effectiveDefaultValue(field)
|
|
236
266
|
return html`
|
|
237
267
|
<md-outlined-text-field
|
|
238
268
|
.name="column-${i}"
|
|
239
269
|
.label="${field.label ?? ''}"
|
|
240
270
|
type="textarea"
|
|
241
|
-
.value="${
|
|
242
|
-
.placeholder="${
|
|
271
|
+
.value="${preFilledValue ?? ''}"
|
|
272
|
+
.placeholder="${defaultValue ?? ''}"
|
|
243
273
|
rows="3"
|
|
244
|
-
?required=${field.required && !
|
|
274
|
+
?required=${field.required && !defaultValue && !preFilledValue}
|
|
245
275
|
supporting-text=${field.description ?? ''}
|
|
246
276
|
></md-outlined-text-field>
|
|
247
277
|
`
|