-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Fix: required validation for multi-select ComboBox (#9788) #9792
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -152,6 +152,10 @@ function ComboBoxInner<T extends object>({props, collection, comboBoxRef: ref}: | |
| let [labelRef, label] = useSlot( | ||
| !props['aria-label'] && !props['aria-labelledby'] | ||
| ); | ||
| let comboBoxProps = removeDataAttributes(props); | ||
| if (props.selectionMode === 'multiple') { | ||
| delete comboBoxProps.isRequired; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we handle this inside the |
||
| } | ||
| let { | ||
| buttonProps, | ||
| inputProps, | ||
|
|
@@ -162,7 +166,7 @@ function ComboBoxInner<T extends object>({props, collection, comboBoxRef: ref}: | |
| valueProps, | ||
| ...validation | ||
| } = useComboBox({ | ||
| ...removeDataAttributes(props), | ||
| ...comboBoxProps, | ||
| label, | ||
| inputRef, | ||
| buttonRef, | ||
|
|
@@ -210,12 +214,14 @@ function ComboBoxInner<T extends object>({props, collection, comboBoxRef: ref}: | |
| if (name && formValue === 'key') { | ||
| let values: (Key | null)[] = Array.isArray(state.value) ? state.value : [state.value]; | ||
| if (values.length === 0) { | ||
| values = [null]; | ||
| // For multiple mode, add required to the hidden input when no values selected | ||
| let required = props.selectionMode === 'multiple' && props.isRequired; | ||
| inputs = [<input key="empty" type="hidden" name={name} form={props.form} value="" required={required} />]; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this actually prevent form submission? I thought |
||
| } else { | ||
| inputs = values.map((value, i) => ( | ||
| <input key={i} type="hidden" name={name} form={props.form} value={value ?? ''} /> | ||
| )); | ||
| } | ||
|
|
||
| inputs = values.map((value, i) => ( | ||
| <input key={i} type="hidden" name={name} form={props.form} value={value ?? ''} /> | ||
| )); | ||
| } | ||
|
|
||
| return ( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is correct. If the value is empty,
validateshould not be called. This should be handled byisRequired.