File tree Expand file tree Collapse file tree 2 files changed +50
-7
lines changed Expand file tree Collapse file tree 2 files changed +50
-7
lines changed Original file line number Diff line number Diff line change @@ -332,15 +332,19 @@ export function buildFieldSchema(
332332 } )
333333 }
334334
335- // Handle options
336- const options = getFieldOptions ( schema )
337- if ( options ) {
338- field . options = options
339- if ( schema . type === 'array' ) {
340- field . multiple = true
335+ // Generate options from schema if no options were provided via x-jsf-presentation
336+ if ( field . options === undefined ) {
337+ const options = getFieldOptions ( schema )
338+ if ( options ) {
339+ field . options = options
340+ if ( schema . type === 'array' ) {
341+ field . multiple = true
342+ }
341343 }
342344 }
343- else {
345+
346+ // Options and fields are mutually exclusive, so we only add fields if no options were provided
347+ if ( field . options === undefined ) {
344348 // We did not find options, so we might have an array to generate fields from
345349 const fields = getFields ( schema , strictInputType )
346350 if ( fields ) {
Original file line number Diff line number Diff line change @@ -235,6 +235,45 @@ describe('fields', () => {
235235 ] )
236236 } )
237237
238+ it ( 'creates options from an enum inside items (deprecated)' , ( ) => {
239+ const schema : JsfSchema = {
240+ type : 'object' ,
241+ properties : {
242+ currency : {
243+ 'type' : 'array' ,
244+ 'items' : {
245+ type : 'string' ,
246+ enum : [ 'usd' , 'eur' , 'gbp' ] ,
247+ } ,
248+ 'x-jsf-presentation' : {
249+ options : [
250+ {
251+ label : 'USD' ,
252+ value : 'usd' ,
253+ } ,
254+ {
255+ label : 'EUR' ,
256+ value : 'eur' ,
257+ } ,
258+ {
259+ label : 'GBP' ,
260+ value : 'gbp' ,
261+ } ,
262+ ] ,
263+ } ,
264+ } ,
265+ } ,
266+ }
267+
268+ const fields = buildFieldSchema ( schema , 'root' , true ) ! . fields !
269+
270+ expect ( fields [ 0 ] . options ) . toEqual ( [
271+ { label : 'USD' , value : 'usd' } ,
272+ { label : 'EUR' , value : 'eur' } ,
273+ { label : 'GBP' , value : 'gbp' } ,
274+ ] )
275+ } )
276+
238277 describe ( 'radio field' , ( ) => {
239278 it ( 'builds a radio field with options' , ( ) => {
240279 const schema : JsfSchema = {
You can’t perform that action at this time.
0 commit comments