mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 01:28:39 +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}}
|
@height={{@height}}
|
||||||
@preview={{@preview}}
|
@preview={{@preview}}
|
||||||
@selection={{@selection}}
|
@selection={{@selection}}
|
||||||
|
@includeNone={{@includeNone}}
|
||||||
id={{@field.id}}
|
id={{@field.id}}
|
||||||
name={{@field.name}}
|
name={{@field.name}}
|
||||||
aria-invalid={{if this.error "true"}}
|
aria-invalid={{if this.error "true"}}
|
||||||
|
@ -21,7 +21,9 @@ export default class FKControlSelect extends Component {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return !this.args.field.validation?.includes("required");
|
return (
|
||||||
|
this.args.includeNone ?? !this.args.field.validation?.includes("required")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
@ -124,6 +124,22 @@ module(
|
|||||||
NO_VALUE_OPTION,
|
NO_VALUE_OPTION,
|
||||||
"it has the none when no value is present and field is not required"
|
"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