@@ -20,7 +20,7 @@ import {
2020export function widgetPrimitive (
2121 parameters : WidgetTypeBaseParameters ,
2222) : PrimitiveWidgetOptions {
23- const { data , schema, uiSchema } = parameters ;
23+ const { schema, uiSchema } = parameters ;
2424 const options = createBaseOptions ( parameters ) ;
2525
2626 // Handle enum types first
@@ -34,20 +34,20 @@ export function widgetPrimitive(
3434
3535 // Handle date/time types
3636 if ( schema . format && [ 'date' , 'date-time' , 'time' ] . includes ( schema . format ) ) {
37- return createDateWidget ( options , schema , data ) ;
37+ return createDateWidget ( options , schema , uiSchema ) ;
3838 }
3939
4040 // Handle primitive types
4141 switch ( schema . type ) {
4242 case 'boolean' : {
43- return createBooleanWidget ( options , uiSchema ) ;
43+ return createBooleanWidget ( options , schema , uiSchema ) ;
4444 }
4545 case 'integer' :
4646 case 'number' : {
47- return createNumberWidget ( options , schema , uiSchema , data ) ;
47+ return createNumberWidget ( options , schema , uiSchema ) ;
4848 }
4949 case 'string' : {
50- return createStringWidget ( options , schema , uiSchema , data ) ;
50+ return createStringWidget ( options , schema , uiSchema ) ;
5151 }
5252 default : {
5353 return options ;
@@ -94,34 +94,39 @@ function createBaseOptions({
9494 placeholder : uiSchema [ 'ui:placeholder' ] ,
9595 readonly : uiSchema [ 'ui:readonly' ] ?? false ,
9696 required,
97+ value : baseValue ,
9798 } ,
9899 label,
99100 level,
100101 path,
101102 pathAsString : dotPath ,
102103 schema,
103- value : baseValue ,
104104 widget : null ,
105105 } ;
106106}
107107
108108function createBooleanWidget (
109109 options : PrimitiveWidgetOptions ,
110+ _schema : WidgetTypeBaseParameters [ 'schema' ] ,
110111 uiSchema : WidgetTypeBaseParameters [ 'uiSchema' ] ,
111112) : PrimitiveWidgetOptions < BooleanInputAttributes > {
112113 const booleanOptions : PrimitiveWidgetOptions < BooleanInputAttributes > = {
113114 ...options ,
115+ element : 'input' ,
114116 html : {
115117 ...options . html ,
116- element : 'input' ,
117118 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 ) ,
119123 } ,
120124 } ;
121125
122126 switch ( uiSchema [ 'ui:widget' ] ) {
123127 case 'Button' : {
124- booleanOptions . html . type = null ;
128+ booleanOptions . element = undefined ;
129+ booleanOptions . html . type = undefined ;
125130 booleanOptions . widget = 'ButtonGroupBoolean' ;
126131 break ;
127132 }
@@ -145,7 +150,7 @@ function createBooleanWidget(
145150function createDateWidget (
146151 options : PrimitiveWidgetOptions ,
147152 schema : WidgetTypeBaseParameters [ 'schema' ] ,
148- data : WidgetTypeBaseParameters [ 'data ' ] ,
153+ _uiSchema : WidgetTypeBaseParameters [ 'uiSchema ' ] ,
149154) : PrimitiveWidgetOptions < DateInputAttributes > {
150155 const type =
151156 schema . format === 'date-time'
@@ -154,13 +159,15 @@ function createDateWidget(
154159
155160 const dateOptions : PrimitiveWidgetOptions < DateInputAttributes > = {
156161 ...options ,
162+ element : 'input' ,
157163 html : {
158164 ...options . html ,
159- element : 'input' ,
160165 type,
161- value : typeof data === 'string' ? data : undefined ,
166+ value :
167+ options . html . value === undefined
168+ ? undefined
169+ : String ( options . html . value as string ) ,
162170 } ,
163- value : typeof options . value === 'string' ? options . value : undefined ,
164171 widget : 'Date' ,
165172 } ;
166173
@@ -175,9 +182,9 @@ function createEnumWidget(
175182 const enumOptions : EnumWidgetOptions = {
176183 ...options ,
177184 enum : undefined ,
185+ element : 'select' ,
178186 html : {
179187 ...options . html ,
180- element : 'select' ,
181188 value : undefined ,
182189 } ,
183190 type : undefined ,
@@ -206,15 +213,17 @@ function createNumberWidget(
206213 options : PrimitiveWidgetOptions ,
207214 schema : WidgetTypeBaseParameters [ 'schema' ] ,
208215 uiSchema : WidgetTypeBaseParameters [ 'uiSchema' ] ,
209- data : WidgetTypeBaseParameters [ 'data' ] ,
210216) : PrimitiveWidgetOptions < NumberInputAttributes > {
211217 const numberOptions : PrimitiveWidgetOptions < NumberInputAttributes > = {
212218 ...options ,
219+ element : 'input' ,
213220 html : {
214221 ...options . html ,
215- element : 'input' ,
216222 type : 'number' ,
217- value : typeof data === 'number' ? data : undefined ,
223+ value :
224+ options . html . value === undefined
225+ ? undefined
226+ : Number ( options . html . value ) ,
218227 } ,
219228 } ;
220229
@@ -246,26 +255,28 @@ function createStringWidget(
246255 options : PrimitiveWidgetOptions ,
247256 schema : WidgetTypeBaseParameters [ 'schema' ] ,
248257 uiSchema : WidgetTypeBaseParameters [ 'uiSchema' ] ,
249- data : WidgetTypeBaseParameters [ 'data' ] ,
250258) : PrimitiveWidgetOptions < StringInputAttributes > {
251259 const stringOptions : PrimitiveWidgetOptions < StringInputAttributes > = {
252260 ...options ,
261+ element : 'input' ,
253262 html : {
254263 ...options . html ,
255- element : 'input' ,
256264 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 ) ,
258269 } ,
259270 } ;
260271
261272 if ( uiSchema [ 'ui:widget' ] === 'Textarea' ) {
262- stringOptions . html . element = 'textarea' ;
273+ stringOptions . element = 'textarea' ;
263274 stringOptions . widget = 'Textarea' ;
264275 } else if ( uiSchema [ 'ui:widget' ] === 'ColorPicker' ) {
265- stringOptions . html . element = 'input' ;
276+ stringOptions . element = 'input' ;
266277 stringOptions . widget = 'ColorPicker' ;
267278 } else {
268- stringOptions . html . element = 'input' ;
279+ stringOptions . element = 'input' ;
269280 stringOptions . widget = 'Text' ;
270281 stringOptions . html . type = 'text' ;
271282 }
@@ -280,8 +291,8 @@ function createStringWidget(
280291 stringOptions . html . type = 'tel' ;
281292 }
282293
283- stringOptions . html . minLength = schema . minLength ;
284- stringOptions . html . maxLength = schema . maxLength ;
294+ stringOptions . html . minlength = schema . minLength ;
295+ stringOptions . html . maxlength = schema . maxLength ;
285296 stringOptions . html . pattern = schema . pattern ;
286297
287298 return stringOptions ;
0 commit comments