View [
f1: field focus
f2: field
]
When run this code cursor get focus in f1
But I want to press enter and focus will be in f2
.
How can I do that?
From inside a on-enter
handler, you need to change the selected
facet of the window face (just the parent face in this case) to point to the face you want to focus on. So your code becomes:
view [ f1: field focus on-enter [face/parent/selected: f2] f2: field ]
If you need to change focus often, you can define a convenient shortcut function:
set-focus: function [face [object!]][
p: face/parent
while [p/type <> 'window][p: p/parent]
p/selected: face
]
view [ f1: field focus on-enter [set-focus f2] f2: field ]
Red/View will provide a built-in set-focus
function in future versions, so you won't have to define it in your own code.