Better way to allow no selection in dropdowns?

In my project, when we use dropdowns, in the Data property our SQL query is usually a union query -

(SELECT -1 as 'Value', 'Select One' as 'Label')
UNION
(SELECT real data here)

This makes ordering the dropdowns a little annoying too because I need to make the ‘Select one’ the first row using an exception, etc. Is there a way to make it so the dropdown always shows a None-Select option without using this data method? Otherwise, currently, when you select a dropdown, its impossible to revert to no selection - image

If you just want the ability to reset a dropdown to -1 so that it says ‘Select One’

You could set a button next to the dropdown, bind the visible property to the dropdown selectedValue != -1, and then give it a script that sets the dropdown selectedValue to -1.
image
image
image

1 Like

This is how I do it in a named query

Select 'ALL' As value, 'All Serials' as label
Union All
SELECT serial AS id, serial
FROM equipment
ORDER BY label

All serials is basically no selection. In the designer I have ALL as the set value so it always defaults to no selection when opening the view.

I played around in changing the text all serials to select one and that droppped it down in the list due to sorting alphabetically. But when I put it in angle brackets it put it back to the top of the list.

So the final code is…

Select 'ALL' As value, '<Select One>' as label
Union All
SELECT serial AS id, serial
FROM equipment
ORDER BY label

To get more complex i have various values filtering the table, so in the drop down I have a custom property.

if ({this.props.value}='ALL',
	"serial >= ''",
	concat("serial = '",{this.props.value},"'")
	)

This basically ignores the drop down value if its ‘All’ or uses the value to filter the table if something else is selected.

Then use that custom property as query strings in a named query…

SELECT serial AS Serial, catagory As Catagory, location AS Location
FROM equipment
WHERE {Serial}
AND {Catagory}
AND {Location}
Order by serial ASC

Drop Down 1 Drop Down