@@ -20,7 +20,7 @@ import {
20
20
export function widgetPrimitive (
21
21
parameters : WidgetTypeBaseParameters ,
22
22
) : PrimitiveWidgetOptions {
23
- const { data , schema, uiSchema } = parameters ;
23
+ const { schema, uiSchema } = parameters ;
24
24
const options = createBaseOptions ( parameters ) ;
25
25
26
26
// Handle enum types first
@@ -34,20 +34,20 @@ export function widgetPrimitive(
34
34
35
35
// Handle date/time types
36
36
if ( schema . format && [ 'date' , 'date-time' , 'time' ] . includes ( schema . format ) ) {
37
- return createDateWidget ( options , schema , data ) ;
37
+ return createDateWidget ( options , schema , uiSchema ) ;
38
38
}
39
39
40
40
// Handle primitive types
41
41
switch ( schema . type ) {
42
42
case 'boolean' : {
43
- return createBooleanWidget ( options , uiSchema ) ;
43
+ return createBooleanWidget ( options , schema , uiSchema ) ;
44
44
}
45
45
case 'integer' :
46
46
case 'number' : {
47
- return createNumberWidget ( options , schema , uiSchema , data ) ;
47
+ return createNumberWidget ( options , schema , uiSchema ) ;
48
48
}
49
49
case 'string' : {
50
- return createStringWidget ( options , schema , uiSchema , data ) ;
50
+ return createStringWidget ( options , schema , uiSchema ) ;
51
51
}
52
52
default : {
53
53
return options ;
@@ -94,34 +94,39 @@ function createBaseOptions({
94
94
placeholder : uiSchema [ 'ui:placeholder' ] ,
95
95
readonly : uiSchema [ 'ui:readonly' ] ?? false ,
96
96
required,
97
+ value : baseValue ,
97
98
} ,
98
99
label,
99
100
level,
100
101
path,
101
102
pathAsString : dotPath ,
102
103
schema,
103
- value : baseValue ,
104
104
widget : null ,
105
105
} ;
106
106
}
107
107
108
108
function createBooleanWidget (
109
109
options : PrimitiveWidgetOptions ,
110
+ _schema : WidgetTypeBaseParameters [ 'schema' ] ,
110
111
uiSchema : WidgetTypeBaseParameters [ 'uiSchema' ] ,
111
112
) : PrimitiveWidgetOptions < BooleanInputAttributes > {
112
113
const booleanOptions : PrimitiveWidgetOptions < BooleanInputAttributes > = {
113
114
...options ,
115
+ element : 'input' ,
114
116
html : {
115
117
...options . html ,
116
- element : 'input' ,
117
118
type : 'checkbox' ,
118
- value : options . value === undefined ? undefined : Boolean ( options . value ) ,
119
+ value :
120
+ options . html . value === undefined
121
+ ? undefined
122
+ : Boolean ( options . html . value ) ,
119
123
} ,
120
124
} ;
121
125
122
126
switch ( uiSchema [ 'ui:widget' ] ) {
123
127
case 'Button' : {
124
- booleanOptions . html . type = null ;
128
+ booleanOptions . element = undefined ;
129
+ booleanOptions . html . type = undefined ;
125
130
booleanOptions . widget = 'ButtonGroupBoolean' ;
126
131
break ;
127
132
}
@@ -145,7 +150,7 @@ function createBooleanWidget(
145
150
function createDateWidget (
146
151
options : PrimitiveWidgetOptions ,
147
152
schema : WidgetTypeBaseParameters [ 'schema' ] ,
148
- data : WidgetTypeBaseParameters [ 'data ' ] ,
153
+ _uiSchema : WidgetTypeBaseParameters [ 'uiSchema ' ] ,
149
154
) : PrimitiveWidgetOptions < DateInputAttributes > {
150
155
const type =
151
156
schema . format === 'date-time'
@@ -154,13 +159,15 @@ function createDateWidget(
154
159
155
160
const dateOptions : PrimitiveWidgetOptions < DateInputAttributes > = {
156
161
...options ,
162
+ element : 'input' ,
157
163
html : {
158
164
...options . html ,
159
- element : 'input' ,
160
165
type,
161
- value : typeof data === 'string' ? data : undefined ,
166
+ value :
167
+ options . html . value === undefined
168
+ ? undefined
169
+ : String ( options . html . value as string ) ,
162
170
} ,
163
- value : typeof options . value === 'string' ? options . value : undefined ,
164
171
widget : 'Date' ,
165
172
} ;
166
173
@@ -175,9 +182,9 @@ function createEnumWidget(
175
182
const enumOptions : EnumWidgetOptions = {
176
183
...options ,
177
184
enum : undefined ,
185
+ element : 'select' ,
178
186
html : {
179
187
...options . html ,
180
- element : 'select' ,
181
188
value : undefined ,
182
189
} ,
183
190
type : undefined ,
@@ -206,15 +213,17 @@ function createNumberWidget(
206
213
options : PrimitiveWidgetOptions ,
207
214
schema : WidgetTypeBaseParameters [ 'schema' ] ,
208
215
uiSchema : WidgetTypeBaseParameters [ 'uiSchema' ] ,
209
- data : WidgetTypeBaseParameters [ 'data' ] ,
210
216
) : PrimitiveWidgetOptions < NumberInputAttributes > {
211
217
const numberOptions : PrimitiveWidgetOptions < NumberInputAttributes > = {
212
218
...options ,
219
+ element : 'input' ,
213
220
html : {
214
221
...options . html ,
215
- element : 'input' ,
216
222
type : 'number' ,
217
- value : typeof data === 'number' ? data : undefined ,
223
+ value :
224
+ options . html . value === undefined
225
+ ? undefined
226
+ : Number ( options . html . value ) ,
218
227
} ,
219
228
} ;
220
229
@@ -246,26 +255,28 @@ function createStringWidget(
246
255
options : PrimitiveWidgetOptions ,
247
256
schema : WidgetTypeBaseParameters [ 'schema' ] ,
248
257
uiSchema : WidgetTypeBaseParameters [ 'uiSchema' ] ,
249
- data : WidgetTypeBaseParameters [ 'data' ] ,
250
258
) : PrimitiveWidgetOptions < StringInputAttributes > {
251
259
const stringOptions : PrimitiveWidgetOptions < StringInputAttributes > = {
252
260
...options ,
261
+ element : 'input' ,
253
262
html : {
254
263
...options . html ,
255
- element : 'input' ,
256
264
type : 'text' ,
257
- value : typeof data === 'string' ? data : undefined ,
265
+ value :
266
+ options . html . value === undefined
267
+ ? undefined
268
+ : String ( options . html . value as string ) ,
258
269
} ,
259
270
} ;
260
271
261
272
if ( uiSchema [ 'ui:widget' ] === 'Textarea' ) {
262
- stringOptions . html . element = 'textarea' ;
273
+ stringOptions . element = 'textarea' ;
263
274
stringOptions . widget = 'Textarea' ;
264
275
} else if ( uiSchema [ 'ui:widget' ] === 'ColorPicker' ) {
265
- stringOptions . html . element = 'input' ;
276
+ stringOptions . element = 'input' ;
266
277
stringOptions . widget = 'ColorPicker' ;
267
278
} else {
268
- stringOptions . html . element = 'input' ;
279
+ stringOptions . element = 'input' ;
269
280
stringOptions . widget = 'Text' ;
270
281
stringOptions . html . type = 'text' ;
271
282
}
@@ -280,8 +291,8 @@ function createStringWidget(
280
291
stringOptions . html . type = 'tel' ;
281
292
}
282
293
283
- stringOptions . html . minLength = schema . minLength ;
284
- stringOptions . html . maxLength = schema . maxLength ;
294
+ stringOptions . html . minlength = schema . minLength ;
295
+ stringOptions . html . maxlength = schema . maxLength ;
285
296
stringOptions . html . pattern = schema . pattern ;
286
297
287
298
return stringOptions ;
0 commit comments