Skip to content

Commit 1623885

Browse files
authored
Attribute multiple of type Field is incorrectly valued when parsed from HalFormsProperty (#511)
1 parent 01fd352 commit 1623885

2 files changed

Lines changed: 94 additions & 1 deletion

File tree

src/state/hal.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ function parseHalField(halField: hal.HalFormsProperty): Field {
287287
label: halField.prompt,
288288
required: halField.required || false,
289289
readOnly: halField.readOnly || false,
290-
multiple: halField.options.multiple as any,
290+
multiple: !('maxItems' in halField.options) || !halField.options.maxItems || halField.options.maxItems > 1 as any,
291291
value: (halField.options.selectedValues || halField.value) as any
292292
};
293293

test/unit/state/hal-forms.ts

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ describe('HAL forms', () => {
415415
name: 'dropdown',
416416
required: false,
417417
readOnly: false,
418+
multiple: true,
418419
options: {
419420
v1: 'l1',
420421
v2: 'l2'
@@ -434,6 +435,7 @@ describe('HAL forms', () => {
434435
name: 'dropdown',
435436
required: false,
436437
readOnly: false,
438+
multiple: true,
437439
options: {
438440
v1: 'v1',
439441
v2: 'v2'
@@ -455,13 +457,104 @@ describe('HAL forms', () => {
455457
name: 'dropdown',
456458
required: false,
457459
readOnly: false,
460+
multiple: true,
458461
dataSource: {
459462
href: '/get-options',
460463
labelField: 'prompt',
461464
valueField: 'value',
462465
}
463466
});
464467

468+
testField(
469+
'dropdown with inline options and undefined maxItems',
470+
{
471+
type: 'text',
472+
name: 'dropdown',
473+
options: {
474+
maxItems: undefined,
475+
inline: [
476+
{
477+
prompt: 'l1',
478+
value: 'v1',
479+
},
480+
{
481+
prompt: 'l2',
482+
value: 'v2',
483+
},
484+
]
485+
}
486+
}, {
487+
type: 'select',
488+
name: 'dropdown',
489+
required: false,
490+
readOnly: false,
491+
multiple: true,
492+
options: {
493+
v1: 'l1',
494+
v2: 'l2'
495+
}
496+
});
497+
498+
testField(
499+
'dropdown with inline options and maxItems == 2',
500+
{
501+
type: 'text',
502+
name: 'dropdown',
503+
options: {
504+
maxItems: 2,
505+
inline: [
506+
{
507+
prompt: 'l1',
508+
value: 'v1',
509+
},
510+
{
511+
prompt: 'l2',
512+
value: 'v2',
513+
},
514+
]
515+
}
516+
}, {
517+
type: 'select',
518+
name: 'dropdown',
519+
required: false,
520+
readOnly: false,
521+
multiple: true,
522+
options: {
523+
v1: 'l1',
524+
v2: 'l2'
525+
}
526+
});
527+
528+
testField(
529+
'dropdown with inline options and maxItems == 1',
530+
{
531+
type: 'text',
532+
name: 'dropdown',
533+
options: {
534+
maxItems: 1,
535+
inline: [
536+
{
537+
prompt: 'l1',
538+
value: 'v1',
539+
},
540+
{
541+
prompt: 'l2',
542+
value: 'v2',
543+
},
544+
]
545+
}
546+
}, {
547+
type: 'select',
548+
name: 'dropdown',
549+
required: false,
550+
readOnly: false,
551+
multiple: false,
552+
options: {
553+
v1: 'l1',
554+
v2: 'l2'
555+
}
556+
});
557+
465558
});
466559

467560
});

0 commit comments

Comments
 (0)