DEV: adds includeNone param to form-kit select (#31162)

This option allows to force the presence of none when a value is
selected.
This commit is contained in:
Joffrey JAFFEUX 2025-02-04 11:46:24 +01:00 committed by GitHub
parent 294ed87a6f
commit 8ad34862e4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 20 additions and 1 deletions

View File

@ -96,6 +96,7 @@ export default class FKControlWrapper extends Component {
@height={{@height}}
@preview={{@preview}}
@selection={{@selection}}
@includeNone={{@includeNone}}
id={{@field.id}}
name={{@field.name}}
aria-invalid={{if this.error "true"}}

View File

@ -21,7 +21,9 @@ export default class FKControlSelect extends Component {
return true;
}
return !this.args.field.validation?.includes("required");
return (
this.args.includeNone ?? !this.args.field.validation?.includes("required")
);
}
<template>

View File

@ -124,6 +124,22 @@ module(
NO_VALUE_OPTION,
"it has the none when no value is present and field is not required"
);
await render(<template>
<Form @data={{hash foo="1"}} as |form|>
<form.Field @name="foo" @title="Foo" as |field|>
<field.Select @includeNone={{false}} />
</form.Field>
</Form>
</template>);
assert
.form()
.field("foo")
.hasNoValue(
NO_VALUE_OPTION,
"it doesn’t have the none for an optional field when value is present and includeNone is false"
);
});
}
);