I'm trying to do the following. I have a TextField (or any other control) and I want to determine focus loss according to user’s input validation.
I’ve read this article https://docs.oracle.com/javase/tutorial/uiswing/misc/focus.html#inputVerification but it seems that JavaFX does not handle focus as Swing does.
What I’m trying to achieve is: “A component's input verifier is consulted whenever the component is about to lose the focus. If the component's value is not acceptable, the input verifier can take appropriate action, such as refusing to yield the focus on the component or replacing the user's input with the last valid value and then allowing the focus to transfer to the next component.”
When a user is focused on a textfield (or any other control) I want to validate user’s input in 3 scenarios:
1) Enter key was pressed (I would listen to the KeyEvent, validate input and, if appropriate, ask to focus on the next control, but I don’t know how to do the latter).
2) TAB key was pressed (I need to intercept the focus change event).
3)Focus is lost (for example by clicking on another control or outside the Stage or even by pressing TAB key)
I need to validate user’s input and decide whether I let focus loss or no. In a way, I need to intercept the focus change event.
I can’t simply listen to de textField.focusedProperty because that only tells me that I’m loosing focus, but I can’t (or at least I don´t know how) stop it from happening.
I tried to get information about focus subsystem in JavaFX but couldn’t find any.
I’d like to know when the engine handles focus events and act according to:
a) The control that is loosing focus (and its content)
b) The possible next control in the focus sequence.
c) If the focus remains in the same Stage o if its send to another Stage or application.
I hope I’ve been clear enough with my explanation and please forgive my English if there are any mistakes.
Thank you very much in advance.
Related
I have a machine with a lot of emergency buttons and for each one I have a signal to the PLC saying it is pressed. So I know which button is pressed.
I also have a KRC4 on the security and I do not have any signal from it to the PLC saying that it's emergency is pressed.
I could go by elimination, if none was pressed, so the robot is. But is not the best option because maybe I just have wire from the buttons disconnected and I will assume that is the robot that is in emergency.
I was thinking about getting a system variable that says it is pressed, but I could not find one. Does someone know how to know if the emergency is pressed programmatically?
maybe this helps:
The following predefined data lists exist in the KR C...:
$MACHINE.DAT
is a predefined data list with exclusively predefined system variables. The machine data
serve the purpose of adapting the controller to the connected robot (kinematic
information, control parameters, etc.). There is a $MACHINE.DAT in both the control
system and the robot system. You cannot create new variables or delete existing ones.
Examples:
$ALARM_STOP Signal for Emergency Stop (controller--specific)
Select (assuming that you have 'English' as selected language) Display-> Input/Outputs->External Automatic. This will open up a window where you can connect almost any event or state in the controller to one of the outputs that you have mapped to your PLC. The events or states are more or less self explanatory. Select one and press Configure and Edit to change the output from a default value to the one you desire.
There is no need for a restart afterwards. Just close the wizard and you are good to go. This is also where you can set up inputs for a remote start of the robot. Post a question if you need more details on this topic. Good luck!
I am currently programming in MS Access VBA. I have a form with a textbox on it. I am executing some code on LostFocus event of the textbox.
However, when I close the form using mouse and by clicking on close button on right-top corner of the form, with cursor in the text box, I have noticed that LostFocus event is getting executed before Form_Unload event.
Is there a way to avoid this?
Also, where can I find priorities of the events?? Or How are priorities decided in VBA?
EDIT:
My exact application is like this.
I have a form in MS Access which is used for accepting users' login credentials.
I want to disble textbox for Password and Login button till a valid Username is entered. I check if the username is valid or not on onLostFocus event. Now, consider a case where this form is closed without entering anything in Username textbox. In that case, onLostFocus event gets executed before Form_Unload event.
However, for normal operation, I require onLostFocus event because, on that event I enable Password textbox and login button.
Could there be a different way of doing it??
The lost focus event is not usually the best event for code. Did you have a specific reason for using it? If so, you will need to add a condition to the execution.
The order of events for an Access form are:
Exit → LostFocus
If you are closing a form, the Exit and LostFocus events occur before
the events associated with closing the form (such as Unload,
Deactivate, and Close), as follows:
Exit (control) → LostFocus (control) → Unload (form) → Deactivate
(form) → Close (form)
-- http://office.microsoft.com/en-ie/access-help/order-of-events-for-database-objects-HP005186761.aspx
"I check if the username is valid or not on onLostFocus event."
Do your validation in the after update event of the username text box ... enable/disable the password text box as appropriate when the username value changes.
You can initially disable the the password text box at form load, assuming the form loads with the username text box empty.
using onDirty or onChange is probably better for what you're doing if it is a control that you're inserting data into. There's a bunch of better choices than onLostFocus. Without knowing anything specific makes it tough to know how to help you more specifically. I'd say just try another on Event, because due to the nature of onLostFocus, it'd be impossible to prepare for this contingency.
It seems for me that best place for validation of user input is in focus-out-event handler of entry type widgets (but this is only my thinking). I try to return TRUE from focus-out-event with idea that this will avoid to transfer focus to next control and keep focus on current widget, but this is not OK (not work as needed).
Which is proper way to suppress of transfering focus to next control in case when validation don't pass and where to put validation code on such widgets (gtkEntry, gtkSpinButton, etc) to be usable with signals invoked with both - mouse and keyboard actions?
That is hardly a good idea... Focus is (should be) always owned by the user. That is, the users should be able to move the focus wherever they see fit. If you try to direct the focus, or prevent moving it, based on any logic you can imagine, you will likely frustrate them.
It will surely frustrate me! Say for example that I wrote a wrong data in a box, and then I say, "hey, that's wrong! I want to select that data over there, copy it and paste it here". But I cannot do that because the program will not let me leave the box where I am now without writing an acceptable data. I have to delete the wrong data and enter something... just not good.
The best way to validate the user entry is when you actually do something with it. Either when you save it or when you make it effective. Then you can even make a pop-up saying that there is an error, and when it is close, move the focus to the first error.
If you feel that the user can benefit from an early warning that he is doing wrong, you can use colors (paint the box yellow/red if there is an error), or add a small error icon next to the box. That is waaaay less disruptive than moving the focus around.
I'm trying to implement a kind of "guided typing" widget for data entry, in which the user's text entry is highly controlled and filtered. When the user types a particular character I need to intercept and filter it before displaying it in the widget. Imagine if
you will, a Unix shell embedded as a webapp; that's the kind of thing I'm trying to implement. I've tried two approaches.
In the first, I extend a TextArea, and add a KeyPressHandler to filter the characters. This works, but the browser-provided spelling correction is totally inappropriate, and I don't see how to turn it off. I've tried:
DOM.setElementProperty(textArea.getElement(),
"spellcheck", "false");
But that seems to have no effect- I still get the red underlines over
"typos".
In the second approach I use a FocusWidget to get KeyPress events, and a separate Label or HTML widget to present the filtered characters back to the user. This avoids the spelling correction issue, but since the FocusWidget is not a TextArea, the browser tends to intercept certain typed characters for internal use; e.g. FireFox will use the "/" character to begin a "Quick Find" on the page, and hitting Backspace will load the previous web page.
Is there a better way to accomplish what I'm trying to do?
You might just be able to use event.preventDefault() on your keypress events to avoid these browser behaviors. Otherwise, maybe a hybrid of the two approaches? Have a hidden TextArea with focus, accepting key events, and then post the typed characters to a separate Label.
There is no specific GWT method on TextBox for this, but this simple line of
GWT code fixes the problem for Chrome (for other browsers, YMMV - it may depend upon how completely they implement HTML5) by setting an attribute on the underlying input element:
myTextBox.getElement().setAttribute("spellCheck", "false");
Perhaps this attribute is a relatively new feature.
I'm trying to count the number of times that text is changed in a given RichEdit control. I considered using events like key down, but that gets messy when you consider keys that don't change the text (like arrows, page up, etc). And how do you make sure you get all of those keys?
It seems it would be simpler to register a callback for a onTextChanged event, if one exists. Is there any way to do something like that?
Well you need to listen to the EN_CHANGE message if your using C++. Note that you also have to call SetEventMask with ENM_CHANGE to receive these notifications unlike a normal edit control will sends these messages by default.