Hello,
I try to update the content and in the future more attributes of an UDButton after click.
Is there any obvious I am doing wrong?
As far as I understood Sync-UDElement is not working with static content.
I would expect that it is working the same way as an text box: e.g. https://gist.github.com/adamdriscoll/f3eacce165e98a601586677855559732
$ButtonID = (New-Guid).Guid
New-UDButton -ID $ButtonID -Text "Click me ..." -OnClick (New-UDEndpoint -Endpoint {
$ButtonID = $ArgumentList[0]
Show-UDToast -Message "successfully clicked button - $ButtonID" -Duration 2000
Set-UDElement -Id $ButtonID -Content { "You clicked the button!" }
<#
Set-UDElement -Id $ButtonID -Attributes @{
text = "You clicked the button!"
}
#>
#no need because its a static content
#Sync-UDElement -Id $ButtonID
} -ArgumentList $ButtonID)
BoSen29
November 29, 2019, 1:43pm
2
Hi @augustin.ziegler !
The $ButtonID variable wonât be avaliable to the endpoint âonclickâ.
I believe whatâs passed in $ArgumentList is the GUID of the onclick endpoint which should be â{GUID}onClickâ
Try storing the buttonâs GUID in a $cache or $session variable and try again. Either that or set a static id on the button.
Should work
@BoSen29
The variable $ButtonID is available and shown in the Show-UDToast message.
Do you have a working code snippet?
BoSen29
November 29, 2019, 2:22pm
4
@augustin.ziegler
Apologies, i missed the -argumentlist part, and just asumed that it would read the default passed variables of the endpoint. :-/
Anywhomst: i canât get it working, and in hindsight i remember seeing a github issue regarding the rework of buttons in 2.5 changed the behaviour with get/set-udelement commands.
opened 06:51AM - 19 Jul 19 UTC
closed 02:32PM - 02 Dec 19 UTC
Button attributes are not working on 2.5.2 as before.
I had the below code when I was using 2.3.2 and it was...
breaking-change
bug
Given @adam âs comments this should be fixed in a PR shortly afterwards, however the issue is still open.
Iâll give the source code a look later tonight and see if i can figure this one out
1 Like
That would help me out a lot as in my opinion this is a basic functionality.
BoSen29
November 29, 2019, 2:30pm
6
@augustin.ziegler
I see your point, havenât actually used set-udelement on a button before myself.
What you can do meanwhile, is write the logic yourself in javascript with the âInvoke-UDJavaScriptâ command available in the nightly builds.
See:
Itâs a quick (given that youâre proficient in javascript) and dirty workaround until we get this bug sorted
Hit me up if you want to go down this road, and need some guidance with the javascript
@BoSen29
As I am not a web developer I really need some help with Invoke-UDJavaScript, can you provide me a code snipped to e.g. change the content (only need text) and the background color of a button via JS?
Sorry for asking but I cannot find any example online except the one you gave me: https://github.com/ironmansoftware/universal-dashboard/blob/master/src/UniversalDashboard/Help/Invoke-UDJavaScript.md
I am looking forward to the fix https://github.com/ironmansoftware/universal-dashboard/issues/978
BoSen29
November 29, 2019, 5:36pm
8
Hi again my man @augustin.ziegler
No worries bruv.
Try with:
Invoke-UDJavaScript -Javascript âvar btn = document.getElementById(â$ButtonIDâ); btn.textContent = â$NewBtnContentâ; btn.style.backgroundColor = â$NewBtnBkGrColorââ
Works in the browser console atleast
@BoSen29
Thanks ⌠I will try that one maybe tomorrow and now will start my weekend. Have a great weekend too âŚ
BoSen29
November 29, 2019, 5:39pm
10
@augustin.ziegler
Anytime bro!
Have a good one!
1 Like
after installing the nightly build your code snipped is working fine, thanks for this workaround
$ButtonID = (New-Guid).Guid
New-UDButton -ID $ButtonID -Text "Click me ..." -OnClick (New-UDEndpoint -Endpoint {
$ButtonID = $ArgumentList[0]
Show-UDToast -Message "successfully clicked button - $ButtonID" -Duration 2000
Invoke-UDJavaScript -Javascript "
var btn = document.getElementById('$ButtonID');
btn.textContent = 'You clicked the button!';
btn.style.backgroundColor = 'green'"
} -ArgumentList $ButtonID)
BoSen29
December 2, 2019, 2:41pm
13
Hi @augustin.ziegler
The PR is in the nightly builds tonight:
ironmansoftware:master
â BoSen29:patch-13
opened 11:33AM - 02 Dec 19 UTC
Should solve the issues!
1 Like
@BoSen29
I tried the nightly built and its not working for me.
Maybe I did something wrong, is it working for you?
Set-UDElement -Id $ButtonID -Content { "You clicked the button!" } -Attributes @{
backgroundColor = 'green'
}
Set-UDElement -Id $ButtonID -Attributes @{
text = 'You clicked the button! Attribute'
backgroundColor = 'green'
}
BoSen29
December 3, 2019, 9:50am
16
Hi @augustin.ziegler ,
Try:
Set-UDElement -Id $ButtonID -Attributes @{
backgroundColor = âgreenâ
text = "You clicked the button!
}
Since the text of a button is part of itâs attributes, and not itâs content.
It might not be included in the nightly build, i honestly have no idea how @adam makes them avaliable.
You may need to build the module from github?
Thanks for the text hint, I will do it with the attribute.
As I installed the newest built the fix should be included:
Nightly build 20191202.2 - b4bff54b2b1bcb52b3963a9dd3b870c1f165d65e Fixes 978 (#1342 )
Changes:
b4bff54b2b1bcb52b3963a9dd3b870c1f165d65e Fixes 978 (#1342 )
6b828cb638f2b552c97fc48a55389511adf9ae08 Fixes #658 (#1338 )
67fce2856cd300c6b875c5d26afa3f8209d9c15c Forgotten console.log (#1333 )
9bb10af84a707b053e12ddb8eb1df9934bc69ea0 Create ping-grid-part2.ps1 (#1328 )
1eae7c4f9e33b16191ae1ca1284aafa8e0210ac5 Fixes #1319 (#1325 )
0c0907aad0c2b01c1986f922a197a99d0149a080 Merge pull request #1326 from ironmansoftware/youtubedemoscripts
cd3597104b3bcdbabbde863f29f96e28dff79c5a Youtube Demo Example Scripts
0b521a5e17abd1fce269fb1dddeb271c2c81cb3f Copy pasta of default theme with edits (#1321 )
fac1cec99efc0b4d20ea812a8993790a07989745 Fixes #1313 (#1316 ) [ #1295 ]
5987af020b4a85baa7b0b531b13022b0a78b9dd2 Add -totop param to select-udelement (#1315 )
BoSen29
December 3, 2019, 11:00am
18
Awesome!
In that case, it should work with the text attribute
Sorry for this miss understanding, I tried with the lastest build and the text attribute and its not working for me. Can you give it a try?
Maybe I am doing something wrong
BoSen29
December 3, 2019, 11:07am
20
Hi again,
Ill check when im done in this meeting!
1 Like