From 5ad09f75644d5645c38adf09ea97e4f4c6948749 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Thu, 5 Dec 2024 13:52:22 +0100 Subject: [PATCH] DEV: adds default option to form-kit select (#30126) This commit will now show a "Select..." option when no value selected and a "None" option when a value is selected, as the first row. It ensures that people don't think a value is selected when it's actually just the html select showing the first available option. --- .../form-kit/components/fk/control/select.gjs | 13 +++++++++ .../components/create-invite-test.gjs | 4 +-- .../form-kit/controls/select-test.gjs | 29 +++++++++++++++++++ config/locales/client.en.yml | 3 ++ 4 files changed, 47 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/discourse/app/form-kit/components/fk/control/select.gjs b/app/assets/javascripts/discourse/app/form-kit/components/fk/control/select.gjs index 3bd705bf069..812d67d8b2b 100644 --- a/app/assets/javascripts/discourse/app/form-kit/components/fk/control/select.gjs +++ b/app/assets/javascripts/discourse/app/form-kit/components/fk/control/select.gjs @@ -3,6 +3,7 @@ import { hash } from "@ember/helper"; import { on } from "@ember/modifier"; import { action } from "@ember/object"; import { NO_VALUE_OPTION } from "discourse/form-kit/lib/constants"; +import { i18n } from "discourse-i18n"; import FKControlSelectOption from "./select/option"; export default class FKControlSelect extends Component { @@ -17,6 +18,10 @@ export default class FKControlSelect extends Component { ); } + get hasSelectedValue() { + return this.args.field.value && this.args.field.value !== NO_VALUE_OPTION; + } +