Hi, I am looking to create the simplest of component based on the custom component template and following Adam’s video on custom component here
I am trying to understand how to do a simple bidirecitonal binding to enable the following thing to happens:
- A textbox is displayed on screen
- User type in the textbox
- Universal dashboard have an endpoint that react to it.
I feel it should be super simple but :
- Events are not received in UD (or are they)
I looked at other JSX files such as UD-Checkbox / UD-Select but I am not quite able to apply that principle to my template.
I used the custom control template on IronmanSoftware repository here and was able to build my component and get it displayed in the dashboard (At last, something that I did properly)
Maybe someone can shine a light on this to help me get started ?
New-DudSearch -Text 'Hello World' -OnChange {New-UDInputAction -Toast 'Hello World'}
The PS1 function definition
New-DudSearch.ps1
function New-DudSearch {
param(
[Parameter()]
[string]$Id = (New-Guid).ToString(),
[Parameter()]
[string]$Text,
[Parameter()]
[ScriptBlock]$OnChange
)
End {
if ($null -ne $OnChange) {
$HasEndpoint = New-UDEndpoint -Endpoint $OnChange -Id $Id
}
@{
assetId = $AssetId
isPlugin = $true
type = "DudSearch"
id = $Id
# This is where you can put any other properties. They are passed to the React control's props
# The keys are case-sensitive in JS.
text = $Text
HasEndpoint = $HasEndpoint
}
}
}
The JSX
import React from 'react';
class DudSearch extends React.Component {
onChanged(e) {
if (this.props.onChange == null) {
return
}
var val = e.target.text;
UniversalDashboard.publish('element-event', {
type: "clientEvent",
eventId: this.props.onChange,
eventName: 'onChange',
eventData: val.toString()
});
}
render() {
return <input type="text" defaultValue={this.props.text}
onChange={this.onChanged.bind(this)} />
}
}
export default DudSearch
Edit: I figured out I needed to use DefaultValue to make the text editable.
I am still looking on how I can send the text value to UD.
I feel like I can’t be really far but I am missing something.