Clearing a Dropdown

I have a form with a lookup for a nullable foreign key associated with a drop down box. I am looking for an option to clear the selection in the drop down box… How can I implement this simple feature?

Thank you.

1 Like

Do you mean to be able to set the property to NULL or something similar by selecting some drop down item?

1 Like

The drop down boxes in the Radzen tool that lets me build the project have a small x (next to the down arrow used to select an item) when the property is nullable: clicking the x will clear any selection. This is also the default behavior of LightSwitch drop down boxes. Can I reproduce this behavior in my apps?

Thanks!

At the moment this can be done by prepending an item to the dropdown list data. You need to find the action which populates the dropdown in the page Load event and change the Value of the Set action to something like
[{ CategoryName: '--None--', CategoryID: null}].concat(${result.value}). The property which determines the value of the dropdown (CategoryID in this example) should be set to null.

Then the dropdown will allow the user to select '-- None --'.

By the way how is this done in LightSwitch? I failed to find any references or demos. We can probably implement something similar. Would appreciate some links on the matter!

Best,
Atanas

Thank you, I will try this. Could you provide the complete code to be added in the Value field since the picture truncates it?

In LightSwitch this is implemented the same way it is in the Radzen GUI for nullable keys: there is a small x next to the down arrow of the drop down box and clicking on the x clears the value in the drop down box. The behavior of the drop down is determined by whether the field is required or not: if the field is required, there is no x. No idea how they implemented that…

The complete code is this:

[{ CategoryName: '--None--', CategoryID: null}].concat(${result.value})

I guess LightSwitch sets the foreign key to NULL just as how my example would work. We will consider implementing something similar by default for non required foreign key (a.k.a lookup) fields.

Best regards,
Atanas