Omitting the empty value in a select field

I found this post for kirby 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.

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.

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.

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.

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.

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.

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.

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

This will be fixed in 3.2.0.

Undocumented option:

empty: false

This will work, though not sure if it was supposed to be discouraged.