Common Questions
How do I obtain the reference of a Control?
There are 2 recommended ways of obtaining the reference of an underlying control. \
1. Execute code on control creation
Use the Control.init attribute to run code on control creation.
ListBox.create [
ListBox.init (fun listBox ->
listBox.Items <- [ 1 .. 3 ]
)
]2. Obtain a view reference via an outlet
Calls the listBox.Set function when the control is created.
Component(fun ctx ->
let listBox = ctx.useState<ListBox>(null)
ctx.useEffect (
handler = (fun _ ->
listBox.Current.Items <- [ 1 .. 3 ]
),
triggers = [ EffectTrigger.AfterInit ]
)
View.createWithOutlet listBox.Set ListBox.create [ ]
)How do I obtain the reference of a Component?
The Component reference can be accessed via ctx.control.
How to set attributes on Component level?
How do I restrict what a user can input in a TextBox / AutoCompleteBox / InputElement ?
This is possible by intercepting the TextInputEvent and modifying its event args. It's important to attach the handler to the tunnelled event. More details about event routing can be found here. In the example below whatever a user types in a TextBox will end up as uppercase text.
Here another example that prevents users from entering anything but numbers.
How to render a Control to an Image?
Managing Focus

Last updated