BANano has a simple system to use events:
HandleEvents: does the same as On, BUT prevents the default behaviour
On: handles one or more events
Off: disables an event
To explain the difference between HandleEvents and the On() call, here is an example:
(1)
(2)
They look very similar, but they behave differently:
In (1), it does go to the inp_keydown we wrote, and it does add the letter to the input field.
In (2), it does also go to inp_keydown, but it does not add the letter to the input field
(2) makes it simple to e.g. make a mask. This for example prevents the user from entering a letter a:
Alain
HandleEvents: does the same as On, BUT prevents the default behaviour
On: handles one or more events
Off: disables an event
To explain the difference between HandleEvents and the On() call, here is an example:
(1)
B4X:
Dim inp As BANanoElement = BANano.GetElement(".inputkeys")
inp.On("keydown", EventHandler, "inp_keydown") ' we do want the origi!nal event still to work
inp.HandleEvents("keyup", EventHandler, "inp_keyup")
(2)
B4X:
Dim inp As BANanoElement = BANano.GetElement(".inputkeys")
inp.HandleEvents("keydown", EventHandler, "inp_keydown") ' we do want the origi!nal event still to work
inp.HandleEvents("keyup", EventHandler, "inp_keyup")
They look very similar, but they behave differently:
In (1), it does go to the inp_keydown we wrote, and it does add the letter to the input field.
In (2), it does also go to inp_keydown, but it does not add the letter to the input field
(2) makes it simple to e.g. make a mask. This for example prevents the user from entering a letter a:
B4X:
public Sub Inp_KeyDown(event As BANanoEvent)
Log(event.ID & " Keydown: " & event.Key)
If event.Key = "a" Then
event.PreventDefault
End If
End Sub
Alain