mirror of
https://github.com/discourse/discourse.git
synced 2025-02-24 17:37:57 +08:00
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:
parent
294ed87a6f
commit
8ad34862e4
@ -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"}}
|
||||
|
@ -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>
|
||||
|
@ -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"
|
||||
);
|
||||
});
|
||||
}
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user