New-UDEndpoint in Onchange?

With Buttons in rows, we can pass data from the row into the onclick handler using
New-UDButton -Onclick{ New-UDendpoint -endpoint {} -ArgumentList $($_)}

Is there something similar that can be added to Select?
It seems like the Endpoint is never executed. (the ‘inside’ toast is never shown)

New-UDSelect -Label "Employee Type" -Option {
   New-UDSelectOption -Name "Select to change" -Value 1 -Selected
   New-UDSelectOption -Name "Fixed Term" -Value 2
   New-UDSelectOption -Name "Senior" -Value 3
   New-UDSelectOption -Name "Student" -Value 4
   New-UDSelectOption -Name "Interns" -Value 5
   New-UDSelectOption -Name "Trainee" -Value 6
   New-UDSelectOption -Name "Expat" -Value 7
   New-UDSelectOption -Name "Director" -Value 8

} -OnChange {
   Show-UDToast -Message "Outside" -Duration 600
   New-UDEndpoint -Endpoint {
      Show-UDToast -Message "Inside" -Duration 600
   }                              
}

Besides the endpoint block not executing, $_ isn’t being populated in the OnChange block. If someone smart could confirm that, I’ll make an enhancement issue on it.

I personally use my inputs as custom inputs as described here:-
https://docs.universaldashboard.io/components/inputs#custom-inputs
and I always seem to get the correct results from the user inputting it. Just throwing it out there as a possible workaround…

P.S Sorry @PorreKaj I totally mis-read the first bit of your question, I do apologise

Not sure that can be used in a grid tho

Did you ever use New-UDEndpoint in a similar fashion before ?
This is to go with endpoints created for Start-UDDashboard and also used when creating custom components.

OnChange is already your endpoint.

For the other part of your question, from within the scriptblock, use $eventdata rather than $_ if you want to get the value of the selected element to use somewhere else.

Code sample
New-UDPage -Name 'home'  -Endpoint {

    New-UDGrid -Title "Process Information" -Headers @("Name", "Process Id", "Start Time", "Responding", 'Select') -Properties @("Name", "Id", "StartTime", "Responding", 'Select')  -Endpoint {
        Get-Process | Select Name, Id, StartTime, Responding -First 100 | % {
            [PSCustomObject]@{
                Name       = $_.Name
                Id         = $_.id
                StartTime  = $_.StartTime
                Responding = $_.Responding
                Select     = New-UDSelect -Label "Employee Type" -Option {
                    New-UDSelectOption -Name "Select to change" -Value 1 -Selected
                    New-UDSelectOption -Name "Fixed Term" -Value 2
                    New-UDSelectOption -Name "Senior" -Value 3
                    New-UDSelectOption -Name "Student" -Value 4
                    New-UDSelectOption -Name "Interns" -Value 5
                    New-UDSelectOption -Name "Trainee" -Value 6
                    New-UDSelectOption -Name "Expat" -Value 7
                    New-UDSelectOption -Name "Director" -Value 8

                } -OnChange {
                    Show-UDToast -Message $eventdata -Duration 600

                }
            }
            
        } | Out-UDGridData
    }

}

References

Thanks for the interest so far. here some more info.

$Eventdata only holds the value of the select, but without info about what row it was modified in its useless.

I originally wanted to be able to place a button in each row on a grid. And the button should pass info into a Modal, based on the content of the row.
With @adam’s help, I was able to come up with the code below, and I basically want something similar for UDselect.

@{Name="Details";Expression={
    New-UDButton -Text "More" -OnClick (
        New-UDEndpoint -Endpoint {
            $EmployeeAD = Get-ADUser $($ArgumentList[0]) -Properties Title,Department,AccountExpirationDate,WWWHomePage,msDS-UserPasswordExpiryTimeComputed,PasswordNeverExpires
            
            $Equipment = Invoke-Sqlcmd2 -ServerInstance SQL.Volund.dk\CIMa -Query "
                SELECT
                    [AssetType]
                    ,[AssetManufacturer]
                    ,[AssetModel]
                    ,[AssetSerial]
                    ,[AssetStatus]
                    ,[AssetSystemName]
                    ,[AssetSystemLastSeen]
                    ,[AssetTag]
                FROM 
                    [CIMa_Assets].[dbo].[Assets] 
                Where
                    [OwnerADObjectGUID]=@OwnerADObjectGUID

            " -SqlParameters @{OwnerADObjectGUID = $($($EmployeeAD.ObjectGUID).ToString())}

            $TableData =  @(
                [PSCustomObject]@{Name = "Username";  Value = $($EmployeeAD.SamAccountName); Sort = "1"}
                [PSCustomObject]@{Name = "Name";  Value = $($EmployeeAD.Name); Sort = "2"}
                [PSCustomObject]@{Name = "Title";  Value = $($EmployeeAD.Title); Sort = "3"}
                [PSCustomObject]@{Name = "Department";  Value = $($EmployeeAD.Department); Sort = "4"}
                [PSCustomObject]@{Name = "Department Name";  Value = $($EmployeeAD.WWWHomePage); Sort = "5"}
                [PSCustomObject]@{Name = "Account Expiration Date";  Value = $(if($EmployeeAD.AccountExpirationDate -eq $null) {"Never"} else {(Get-Date ($EmployeeAD.AccountExpirationDate)).tostring("yyyy-MM-dd HH-mm-ss")}); Sort = "6"}

            ).GetEnumerator()


            Show-UDModal -Header {
                New-UDHeading -Size 4 -Text "Here's what we have on $($EmployeeAD.Name)"
            } -Content { 
                New-UDCard -Title "Account Details" -Content {
                    New-UDTable -Headers @("Attribute", "Value") -Endpoint {
                        $TableData | Sort-Object Sort | Out-UDTableData -Property @("Name", "Value")
                    }
                }
                New-UDCard -Title "Assets" -Content {
                    New-UDGrid -Headers @("Type","Status","Manufacturer","Model","Serial","SystemName","ID") -Properties @("AssetType","AssetStatus","AssetManufacturer","AssetModel","AssetSerial","AssetSystemName","AssetTag") -PageSize 20 -Endpoint {
                        $Equipment | Select-Object -Property AssetType,AssetStatus,AssetManufacturer,AssetModel,AssetSerial,AssetSystemName,AssetTag | Out-UDGridData
                    }
                }
            }
        } -ArgumentList $($_.ObjectGUID) 
    )

}}

You know, looking at the UDbutton code, the solution is simple: Replace the -OnChange Curly brackets with parentheses

@{Name="test";Expression={
    New-UDSelect -Label "Employee Type" -Option {
        New-UDSelectOption -Name "Select to change" -Value 1 -Selected
        New-UDSelectOption -Name "Fixed Term" -Value 2
        New-UDSelectOption -Name "Senior" -Value 3
        New-UDSelectOption -Name "Student" -Value 4
        New-UDSelectOption -Name "Interns" -Value 5
        New-UDSelectOption -Name "Trainee" -Value 6
        New-UDSelectOption -Name "Expat" -Value 7
        New-UDSelectOption -Name "Director" -Value 8
        
        } -OnChange (
        New-UDEndpoint -Endpoint {
            Show-UDToast -Message "$($_.ADUSername), $EventData"
        } -ArgumentList $($_)     
        )                         
}}

I won’t be using this, as I already have found another method, but the code is up for grabs.

The end result, is a somewhat bloated grid.
But it allows for quickly making changes to rows.
Simply select a value in the drop down, and the OnChange fires and immediately updates the user