17
Views
10
Comments
Solved
Dropdown default value in ODC
Question

Is it possible to select the default value for a dropdown directly in the widget, without using any JS or clientAction to set the variable associated with the dropdown, directly from the widget settings?

I have tried using the "Empty Text" field, but this doesn't seem to be a valid option, only an additional field displayed in the dropdown.

oml attached (ODC)

IS_FormTest.oml
2023-10-16 05-50-48
Shingo Lam
Solution

In OnAfterFetched of the aggregate GetAppointmentStatusById, you can set the default value there for the fields of your form

2023-10-16 05-50-48
Shingo Lam

I open your oml, its O11, not ODC. Is it right one?

2023-10-16 05-50-48
Shingo Lam

cannot open in O11, some prerequisites are not matched

2023-10-16 05-50-48
Shingo Lam

In fact, I think the code generated will be in reactjs which will apply the 2-way binding method. Which means everything to interact, you must do it via the associated variable.

You can set default value of the associated variable to let the dropdown prefilled at the begining.


DropdownTesting.oml
2025-04-08 05-20-35
Ilay
Staff

Hi @Shingo Lam 

Thank you for the feedback.

It is an ODC app, I checked it again, just in case. Not sure why you are getting that error message?


I am also having the same error message when trying to open your OML. Will try a different version later.

odc_form_test.png
2023-10-16 05-50-48
Shingo Lam

if the below variable has data, the dropdown will auto select it 
My sample can be check here: https://personal-zfpr4idz-dev.outsystems.app/DropdownTesting/ 

2025-04-08 05-20-35
Ilay
Staff

you are right on the point, @Shingo Lam . Issue is that the variable has no data, as the form is for a new request. I wanted to pre-populate some of the fields. Looks like I have to manipulate the variable.

Appreciate your responses.

2023-10-16 05-50-48
Shingo Lam
Solution

In OnAfterFetched of the aggregate GetAppointmentStatusById, you can set the default value there for the fields of your form

2025-04-08 05-20-35
Ilay
Staff

Thanks @Shingo Lam

So, my take is that "it is not possible to set a default value for a dropdown DIRECTLY in the widget, without calling a client action"...

Since there isn't a way to do this directly in the widget settings, i believe your suggestion is a very reasonable answer.

2023-10-16 05-50-48
Shingo Lam

thank you

2016-04-22 00-29-45
Nuno Reis
 
MVP

The dropdown works the same way in all OutSystems versions. The value it has at any given time is the value in the variable.

The default value is the value in the variable before it loads.

The current value being shown is the value in the variable.

The value submitted is submitted in the variable.

The dropdown is just a tool for humans to select the value, but the information is stored in the variable.

You can and should set the value at OnInitialize, even before the list of options is loaded. 

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.