Dropdown 'null / empty' value

UI Components for Vue
Post Reply
ricombnation
Posts: 24
Joined: 11 Jan 2022, 10:54

20 Jan 2022, 10:07

I'm looking for a possibility to have a null / empty / all option for a dropdown. I thought something like this for the options would work:

Code: Select all

[
 {"id":null,"name":"All Categories"},
 {"id":1,"name":"Category 1"},
 {"id":2,"name":"Category 2"},
 {"id":3,"name":"Category 3"}
]
Unfortunately it doesn't - the name for the null value is never displayed. I stumbled upon this https://github.com/primefaces/primevue/issues/736 which is kind of an explanation but not really a solution.

I could fall back to a select, but then the styling is not consistent and the filter function with the clear button also makes the ux inconsistent in this case.

Any other ideas?

ricombnation
Posts: 24
Joined: 11 Jan 2022, 10:54

20 Jan 2022, 11:44

I figured out a workaround - set the placeholder and add an option with a null value and the same name as the placeholder. E.g.

Code: Select all

<Dropdown
  placeholder="All Categories"
  :options="[{id: null, name: 'All Categories'}, ...categories]"
  option-label="name"
  option-value="id" />
... and the options:

Code: Select all

categories = [
 {"id":1,"name":"Category 1"},
 {"id":2,"name":"Category 2"},
 {"id":3,"name":"Category 3"}
]

Post Reply

Return to “PrimeVue”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest