Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/components/form/fields/ListboxField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ export function ListboxField({
description,
helpText,
}: ListboxFieldProps) {
const [, { value }, { setValue }] = useField({ name })
type ItemValue = typeof items[number]['value'] | undefined
const [, { value }, { setValue }] = useField<ItemValue>({
name,
validate: (v) => (required && !v ? `${name} is required` : undefined),
})

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't realize you could just do this. nice!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. In practice the error message isn't showing (it's not actually wired up) but that's fine for now. The behavior of not letting us submit until something is selected is what we're really going for.

return (
<div className="max-w-lg">
<div className="mb-2">
Expand Down
4 changes: 2 additions & 2 deletions app/forms/network-interface-create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ export default function CreateNetworkInterfaceSideModalForm({
name="vpcName"
label="VPC"
items={vpcs.map(({ name }) => ({ label: name, value: name }))}
// required
required
/>
<SubnetListbox
id="nic-subnet"
name="subnetName"
label="Subnet"
vpcNameField="vpcName"
vpcs={vpcs}
// required

This comment was marked as resolved.

required
/>
<TextField id="nic-ip" name="ip" label="IP Address" />
</SideModalForm>
Expand Down