How to set selected index/value of UDSelect

I’m trying to create a UDSelect, then dynamically change it’s selected index (or value) to a certain value. However, I’ve not been able to accomplish this no matter what I try. In my mind, one of the two lines in the -OnClick handler below should work, but when clicked, nothing happens. Any help would be appreciated.

New-UDSelect -Id 'test-select' -Option {
    New-UDSelectOption -Name ' ' -Value ' '
    New-UDSelectOption -Name 'Test' -Value 'Test'
}

New-UDButton -Text 'Click Meh!' -OnClick {
    Set-UDElement -Id 'test-select' -Attributes @{'value'='Test'}
    (Get-UDElement -Id 'test-select').Attributes['value'] = 'Test'
}

Hey JM I see you put a very similar bug report up on github: https://github.com/ironmansoftware/universal-dashboard/issues/872

I am thinking your troubles here all come back to what you originally reported. I had a big post with a number of tests - but honestly the behaviour has been really flakey for me.

Event with/withouth the workaround AND using latest builds - tried testing a combo of Set-UDElement and Sync-UDElement and was not able to get this working at all.

I’ll add some notes to the GitHub issue and see if we can get this issue re-opened. Even with the workaround, it seems a bit broken at times. Seems the New-UDSelect is confusing quite a few people and causing some problems for something that can be a simple and VERY handy control.

1 Like