File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -147,6 +147,10 @@ function convertToOptions(nodeOptions: JsfSchema[]): Array<FieldOption> {
147147 * Get field options from schema
148148 */
149149function getFieldOptions ( schema : NonBooleanJsfSchema ) {
150+ if ( schema [ 'x-jsf-presentation' ] ?. options ) {
151+ return schema [ 'x-jsf-presentation' ] . options
152+ }
153+
150154 if ( schema . oneOf ) {
151155 return convertToOptions ( schema . oneOf || [ ] )
152156 }
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