Hello, I’m back making odd things in Universal Dashboard again. Currently, I’m attempting to dynamically add UDSelect fields to a New-UDInput. I’ve been able to accomplish this perfectly, just the way I want. The issue now is, I can’t interact with said fields. Since my fields are dynamically generated, I can’t manually add their names to the param block in the endpoint. That means I can’t access the values in them at all, ultimately making them pretty but useless. I also thought to reference them via Get-UDElement
, but the UDSelect fields don’t seem to have an ID added to them like all other fields do. Has anyone else ran into that issue? Thanks in advance!
My relevant code is below:
New-UDElement -Tag 'div' -Id 'new-transfer-form' -Endpoint {
if($Cache:BulkTransfer) {
New-UDInput -Title 'Bulk Transfer:' -Content {
Connect-MmAccount -Credential $Cred
$Session:UDFs = Get-MmUdfList
Disconnect-MmAccount
New-UDInputField -Type textarea -Name 'DomainNames' -Placeholder "example.com`t`tAuthCode1`nexample2.com`t`tAuthCode2"
Foreach($UDF in $Session:UDFs) {
New-UDInputField -Type select -Name $UDF.name -Values (@(' ')+$UDF.options)
}
} -Endpoint {
param($DomainNames)
Show-UDToast -Message "Domain Name: $($p2)" -Duration 6000 -Title “Error” -Position topRight -BackgroundColor “#FF7F7F”
if($null -ne $DomainNames) {
$Cache:TransferOrder = [System.Collections.ArrayList]@()
$Items = $DomainNames.Split("`n").Where({$_ -notin $null,''})
for($i=0;$i -lt $Items.count;$i++) {
if($null -ne $Items[$i]) {
$DomainName = ($Items[$i] -split '\s+')[0]
$AuthCode = ($Items[$i] -split '\s+')[1]
if($null -notin $DomainName,$AuthCode) {
Show-UDToast -Message "Domain Name: $($DomainName) AuthCode: $($AuthCode)" -Duration 6000 -Title “Error” -Position topRight -BackgroundColor “#FF7F7F”
$Cache:TransferOrder.Add([PSCustomObject]@{
Domain=$DomainName
Authcode=$AuthCode
})
$ValidationError = $false
} else {
$ValidationError = $true
Write-Error "Invalid Domain/AuthCode Pair on line #$($i)"
}
} else {
$ValidationError = $true
Write-Error "Invalid Domain/AuthCode Pair on line #$($i)"
}
}
if(!$ValidationError) {
New-UDInputAction -Content @(
New-UDCard -Title 'Transfer Order Details' -Content {
New-UDTable -Headers @('Domain Name', 'Auth Code') -Endpoint {
$Cache:TransferOrder | Out-UDTableData -Property Domain,Authcode
}
}
)
}
} else {
Write-Error 'Please enter data before submitting.'
}
}
}
}