Make a button click from -onenter

Hi,
With PSU 2.9 we have a perfect function that’s called -OnEnter but now I can’t for the life of me find out how I can make a button with a specific ID to “Click” when hitting enter. Is it possible?

do you mean -OnEnter the parameter? I’ve only seen this in the documentation for New-UDTextBox here: Textbox - PowerShell Universal

From what I understand buttons dont have this parameter, they only have -OnClick.

Why not just put whatever code you want inside the -OnEnter scriptblock for your textbox?
Alternatively if you want the same code in both but dont want to duplicate it, you could dotsource a file, use a function, or an API endpoint

I have both button and I want to use -OnEnter for Textbox.
I don’t want the code to be in both.
So I was thinking something like:

-OnEnter {
Click-UDButton -iD “button”
}

or similar.

The example in the docs is doing that. Invoke-UDEndpoint is calling the submit button.

New-UDTextbox -OnEnter {
    Invoke-UDEndpoint -Id 'submit'
}

New-UDButton -Id 'submit' -OnClick {
    Show-UDToast -Message 'From Textbox'
}

Sorry I did completely miss that! Thanks!

I’m getting error on this;

            New-UDGrid -Item -ExtraLargeSize 4 -LargeSize 4 -MediumSize 4 -SmallSize 6 -Children {
                New-UDTextbox -Id "txtGroupNameStart" -Icon (New-UDIcon -Icon 'users') -Label "Ange gruppnamn (Wildcard *)" -FullWidth -onEnter {
                    Invoke-UDEndpoint -Id 'MainSearch'
                }
            }
            New-UDGrid -Item -ExtraLargeSize 3 -LargeSize 3 -MediumSize 3 -SmallSize 4 -Children { 
                New-UDButton -Icon (New-UDIcon -Icon 'search') -Size large -OnClick {
                    $GroupName = (Get-UDElement -Id "txtGroupNameStart").value

                    if ([string]::IsNullOrEmpty($GroupName)) {
                        Sync-UDElement -Id 'GroupSearchStart'
                    }
                    elseif ($GroupName.EndsWith('*')) {
                        New-MultiSearch -ActiveEventLog $ActiveEventLog -SearchFor $GroupName -txtBoxMultiSearch "txtGroupNameStart" -MultiSearchObj "Group" -ElementSync 'GroupSearchStart'
                    }
                    else {
                        Sync-UDElement -Id 'GroupSearchStart'
                    }
                } -Id 'MainSearch'
                #New-ADGrp -EventLogName $EventLogName -ActiveEventLog $ActiveEventLog -User $User -LocalIpAddress $LocalIpAddress -RemoteIpAddress $RemoteIpAddress
            }

There error is;
image

@adam

@adam can you reproduce my issue or is it something that’s wrong in my config?
I always get this error.

It was in 2.9.0 I have not tried with 2.9.2

Try include the -Session parameter on Invoke-UDEndpoint. The problem here is that you can have global endpoints (like pages) and session specific endpoints like the button. This used to make more sense in v2 when pages weren’t dynamic by default. Sorry about that.

 Invoke-UDEndpoint -Id 'MainSearch' -Session
1 Like

@adam I am trying this out too, but with “-Session” i only get:
image

                New-UDTextbox -Id "User-Info_Search_Textbox" -Label "Username" -AutoFocus -OnEnter { Invoke-UDEndpoint -Id "User-Info_Search_Button" -Session }
                New-UDButton -Text "Search" -Id "User-Info_Search_Button" -OnClick {
                    $Session:Value = (Get-UDElement -Id "User-Info_Search_Textbox").value 
                    if ( $Session:Value.length -lt 3) {
                        Show-UDToast -Message "$( $Session:Value) is too short. It needs to be atleast 3 chars." -CloseOnClick -Duration 15000 -Icon exclamation -IconColor Red
                    }
                    else {
                        Sync-UDElement -Id "User-Info_Dynamic"
                    }
                }
            } 

For some reason the $Session scope isn’t working here. I can reproduce that. If I change it to a regular variable, then it works. That said, I realize that isn’t what you’re after.

I just tested this on 3.0.1.

The above code still doesn’t work, with the same error.
Without “-Session” it wont even find the button.
With “-Session” it finds it, but gives the same error regarding “Session:Values” (Cannot find path ‘Session:Value’ because it does not exist).
When clicking the button normally it works.

I saw that the issue was closed: Invoke-UDEndpoint doesn’t work with $Session · Issue #1195 · ironmansoftware/issues · GitHub
So I am wondering if I am on a wrong version of some sort?

I can reproduce this on v3 as well. I’ve reopened that issue.

1 Like

@adam I saw that the GitHub issue is closed again, but something still isn’t working quite right.

We’re now running 3.0.2 and while it works fine in our test env, there are bugs in our prod env.
Also running the command with “-Session”
I can’t quite say why, but it seems that with multiple sessions running simultaneously, the session variable from other sessions gets used - can’t say that is exactly what happens for sure though, more of a hunch.

When using the button itself instead of the onEnter function (with Invoke-UDEndpoint in it) it all works fine. Once onEnter is used, the session seems to break and even the button acts weirdly.

I’ve reactivated the issue to see if I can reproduce this behavior.