jquery to change special list value option in combo?

Hi there,

I have a use case where i have a combo box in a reusable webblock with a special list value / option, and i want to change the option name depending on input to the webblock.

With OS functions this cannot be done if i am correct as an expression cannot be used, from another post (https://www.outsystems.com/forums/discussion/21444/how-to-display-specialvalue-last-in-the-list-and-its-value/) i saw, i was wondering if renaming the special list option is possible with jquery?

Something like this:

"
<script>
    var cb = $('#" + ComboBox.Id + "');
    var o = $(cb).children()[0];
    $(cb).children()[0].rename('new name');
</script>
"

Thanks ahead,

Wilko

Solution

Hello Wilko,

Instead of using the Special List, why not insert the "special value" in the list you are providing (if you are providing an entity, change it to a list), as the first element of the list, with a negative ID?

Cheers.

P.S. This way you wouldn't have to deal with JavaScript at all.

Solution

If you really want to use jQuery you only need to change your "rename" to "text" and it should work. 

Like this:

"
<script>
    var cb = $('#" + ComboBox.Id + "');
    var o = $(cb).children()[0];
    $(cb).children()[0].text('new name');
</script>
"

wilko odijk wrote:

Hi there,

I have a use case where i have a combo box in a reusable webblock with a special list value / option, and i want to change the option name depending on input to the webblock.

With OS functions this cannot be done if i am correct as an expression cannot be used, from another post (https://www.outsystems.com/forums/discussion/21444/how-to-display-specialvalue-last-in-the-list-and-its-value/) i saw, i was wondering if renaming the special list option is possible with jquery?

Something like this:

"
<script>
    var cb = $('#" + ComboBox.Id + "');
    var o = $(cb).children()[0];
    $(cb).children()[0].rename('new name');
</script>
"

Thanks ahead,

Wilko

Hi wilko,

On the screen Preparation, just before the End Node, add a RunJavascript Server Action (from the HTTPRequestHandler Extension), and add the following to the Script parameter:

"$('#" + <YourComboRuntimeId> + " option[value=__ossli_0]').text('" + EncodeJavascript(<YourCustomTextVariable>) + "');"

Replace <YourComboRuntimeId> with the Runtime Id of your Combo Box, and <YourCustomTextVariable> with the text you want to display for Value 0 on your Special List.

One very important thing to take into consideration, if you have any kind of AjaxRefresh on the Combo Box or one of its parents, you will have to manually run the above Javascript again, as it will be defaulted to the setting you define on development time.

Hope this helps.

Thank you.

Best regards,

Paulo Moreira


Dear Eduardo, Tiago and Paulo,

Thanks for your help.

I tried all 3 solutions, but I managed only to get the one from Eduardo working. I am sure all 3 are good solutions, but my JavaScript is not good, that is the probable cause of not getting it working, rather than the proposed solutions of Tiago and Paulo. Eduardo's does what needs to be done for my situation, so i'll go ahead and mark that one as my solution. Too bad i can't mark all of them being a solution.

Thanks again,

Wilko