Value of New-UDSelect if no choice?

Hello,

When no choice is made on a drop-down list where a value is preselected it is not possible to find the value with Get-UDElement.
Is it a bug or a bad coding on my part?

My version of Universal Dashboard : 2.7.0

Here is my code :

$Cache:Companies = @("A", "B", "C", "D", "E", "F", "G")

New-UDPage -Url "test" -Title "Test" -Endpoint {
	
	$Company = "D"
	New-UDSelect -Id "select" -Label "Company" -Option {
		$Cache:Companies | ForEach-Object {
			if ($_ -eq $Company)
			{
				New-UDSelectOption -Name $_ -Value $_ -Selected
			}
			else
			{
				New-UDSelectOption -Name $_ -Value $_
			}
		}
	} -OnChange {
		Show-UDToast -Title "onchange" -Message $EventData
	}
	
	New-UDButton -Text "test" -OnClick {
		$Test = (Get-UDElement -Id "select").Attributes['value']
		Show-UDToast -Title "button" -Message $Test
		
	}
}

Hello @bryce426 sure I heard of this before being mentioned…and digging a little deeper got me to the result:- https://github.com/ironmansoftware/universal-dashboard/issues/694
So basically use the -DefaultValue parameter to over-come this problem. Peace

2 Likes

Thank you @psDevUK for your answer. My piece of code is just an example. In the real form, I do not have the possibility to use NEW-UDInput because of the complexity of the form (button, formatting, etc …). Does a solution exist with New-UDSelect?

Hio @bryce426
From looking at the source code, it seems to be a bug.
Could you make a bug report on GitHub?

Should be a simple solution.

The issue is open : https://github.com/ironmansoftware/universal-dashboard/issues/1302

2 Likes