how do we handle events?
it have a couple of onplay onpause and the like, but how do I “parse” this between react and powershell?
adam
October 3, 2019, 1:56pm
2
In PowerShell, you need to accept a script block or endpoint so that it gets registered with UD. This is how the checkbox is doing it.
[Parameter()]
[Switch]$Checked,
[Parameter()]
[Switch]$FilledIn,
[Parameter()]
[Switch]$Disabled,
[Parameter()]
[object]$OnChange
)
if ($null -ne $OnChange) {
if ($OnChange -is [scriptblock]) {
$OnChange = New-UDEndpoint -Endpoint $OnChange -Id ($Id + "onChange")
}
elseif ($OnChange -isnot [UniversalDashboard.Models.Endpoint]) {
throw "OnChange must be a script block or UDEndpoint"
}
}
@{
type = 'ud-checkbox'
In JavaScript, you need to use the UniversalDashboard global object and publish the element-event message. This will send it back to the server to invoke the endpoint.
this.setState({
checked: e.target.checked
});
if (this.props.onChange == null) {
return
}
var val = e.target.checked;
UniversalDashboard.publish('element-event', {
type: "clientEvent",
eventId: this.props.onChange,
eventName: 'onChange',
eventData: val.toString()
});
}
render() {
return <Checkbox
checked={this.state.checked}
1 Like
Oh sweet ! thanks man! looking forward to play with it