Omitting the empty value in a select field

#1

I found this post for kirby 2:
https://forum.getkirby.com/t/omitting-the-empty-value-in-a-select/8412/2

Is it sill not possible to remove the empty (dash) state of a select field? I want to make sure, that it is not possible to select the empty state. I could make the field required, but there is still the empty dash.

#2

I think if you set the default value for the field, it will stamp that into the content file when the page gets created. The user can then update it as required, but you can be sure a value will be there, even if its a default rather then empty. I don’t think its possible to remove the empty state though, if a user was to set it to that after page creation.

You could probably use a page update hook to check the value is not empty and set it to the default value if it is.

#3

If you want to make it impossible that the user selects the empty state and make sure that a value is filled in, you have to combine default: some value and required: true.

Note that the default value only kicks in at page creation, not afterwards.

#4

Thanks, Yes I set the default value, that works. but I don’t get it, why we can’t remove or hide the empty state. Would be less confusing for editor, if they can’t select that state.

#5

But you are right, the empty state remains as option and can’t be removed. I think that is not how this should behave, actually.

#6

Actually its pretty common place to have a blank entry as the first option on a select, from a front end point of view. It’s even that way Mozillas HTML element reference. In Kirby’s case its been set to “-” rather “Please choose an option”.

But I do understand the argument for being able to remove it.

#7

If you use a multi-select field with max: 1, required and default and list layout, you can get rid of the empty option. Looks different, though.

#8
#9

Thanks for your effort, @texnixe. So maybe it changes in the future :wink: