JavaFX: default button won't fire events - events

In my code I have bound the defaultProperty of a button to some other properties like so:
BooleanBinding isAddResourceButtonDefault
= resourceNameTextField.focusedProperty().or(
resourceTypeComboBox.focusedProperty()).or(
divisibleResourceCheckbox.focusedProperty().or(
maxInstancesTextField.focusedProperty()).or(
addResourceButton.focusedProperty()));
addResourceButton.defaultButtonProperty().bind(isAddResourceButtonDefault);
The problem is that the addResourceButton won't fire absolutely any events on pushing Enter - neither OnAction, nor OnKeyPressed.
The default property gets set just fine - I double checked (using output and ScenicView). ScenicView also doesn't show any events being fired upon hitting keys. Any ideas?

I believe TextFields (and other TextInputControls) process and consume key events that occur on them. So pressing Enter on a text field will not fire an action event on the default button (because the key event never reaches the Scene).
If you are just trying to fire the button's action event handler when enter is pressed in one of the text fields, just add the same event handler to the text fields. E.g.
EventHandler<ActionEvent> addResourceHandler = event -> {
System.out.println("Add resource");
// ...
};
addResourceButton.setOnAction(addResourceHandler);
resourceNameTextField.setOnAction(addResourceHandler);
maxInstancesTextField.setOnAction(addResourceHandler);

Related

How to avoid events to popup to accordion

I have an Accordion Panel whose summary is a search field:
When the content of the search field change, the panel shall be opened and show search result.
It happens that the events in the search field pop-up to the the tab that consequently opens and closes the tab when space or enter keys are pressed. I tried to wrap the summary in a special div that prevents pop-up:
class MyDiv extends Div {
public MyDiv(Component... components) {
super(components);
getElement().executeJs("addEventListener('keydown', (e) => {console.log('pop up prevented'); e.stopPropagation();});");
}
}
...
accordion.add(searchAccordionPanel = new AccordionPanel(new MyDiv(searchField),
searchItemsPage = new MenuItemsPage(this)));
And in fact I see the events intercepted ("pop up prevented" on console) but for some reason the accordion still responds to keypress. I have also tried keyup and keypress events, same result.
Maybe Vaadin transmit another event? Can anybody suggest a solution?
By default TextField is in eager value change mode, i.e. it emits value change after each key stroke. This does not fit in your use case. You can use textField.setValueChangeMode(ValueChangeMode.LAZY) for example. Then TextField will emits value change after user has paused typing. There are also couple of other modes, pick the one that fits the use case the best. Some times it requires trial and error.

VB6 _Validation event not firing when tabbing to Cancel button with CausesValidation = False

I have a situation similar to the following simplified description:
A form with a TextBox (call it txtQty) in which a user can enter an integer. The event txtQty_Validate is used to validate the user input and force them to correct any errors before changing focus. This works great with all other controls on the form except for said txtQty. I assume that this is because the Cancel button on the form has the property CausesValidation necessarily set to false; thus when the user Tabs from txtQty to the Cancel button (whose TabIndex is next) it does not appropriately trigger the txtQty_Validation event.
My first instinct was to simply go to the txtQty_KeyPress event (which I am already using to make the RETURN key behave as TAB key) and capture the TAB key and temporarily toggle the CausesValidation property to allow the txtQty_Validation event to fire. However, it seems as though capturing the TAB key is not as easy as I had thought it would be.
Any suggestions? I assume that this cannot be the first time anybody creating a Form has come across such a situation.
Thanks
You could try this in the Cancel GotFocus event.
Dim b As Boolean
Call txtQty_Validate(b)
If b Then txtQty.SetFocus
Assuming you have something like this
Private Sub txtQty_Validate(Cancel As Boolean)
If Not IsNumeric(txtQty.Text) Then
Cancel = True
End If
End Sub

Event for selecting an option even though value is not changed in dijit.form.Select.

I need help in figuring out the event that is fired when I select a dropdown value from dijit.form.Select. I already know of the onChange event and would like to know an event which fired even when the value is not changed.
Use Case
I am using dijit.form.Select in my project. I have some values like {Multiple,a,b,c,d} in this select drop down. When I select Multiple then it launches the pop up dialog. When I select other values a,b,c or d then that value gets set in that drop down.
Currently I catch onChange event to check if user has selected "Multiple" value so that I can launch the pop up dialog.
Now here is one issue. 1. Lets assume that by default selected value is a. 2. Now I select Multiple, onChange gets fired and pop up dialog gets launched. 3. Now again if I select Multiple then onChange event won't be fired and thus code would not launch pop up dialog.
I want to launch this dialog every time user selects "Multiple" value in the dropdown. Any suggestions to do this? I have tried useing onClick, onBlur and onFocus events but they are not of much use to me.
Please help.
You can Capture the 'onExecute' event of the dropDown of the dijit.form.Select widget for this behaviour. However, keep in mind that you wont get the newVal as an argument to the function for this event. to get the new value, use the following line as the first line of your function:
var newVal = this.focusedChild.option.value;
This will work for sure :)

how I can check the leave event is occured in other buttons click event in C#

I have called a leave event for a a text box and in it called another buttons event named Retrieve button. so now I just want to check in this retrieve button event weather the text box's leave event is called or not?
When you call the retrieve button event from the text box leave (blur) event you could simply add a flag into the eventArgs that you can check in the retrieve button. This flag would only be set when you implicitly call the retrieve button even from the text box leave event.
This would mean that if the retrieve event is called from other places the flag would not be set so you could tell that the call definitely came from the button leave event.

Telerik MVC treeview - dynamically added textbox - can't click to change cursor position

I have drag drop enabled and i know that is the cause of my problem. I am allowing the tree nodes to be editable and on edit i show a textbox, but when you click in it to change the cursor position, nothing happens.
if i disable drag/drop then it is not an issue. I have tried to stop the event from bubbling up by putting click event handler for the textbox and doing preventdefault, stopPropagation, returning false, but that doesn't work.
I have also disabled the li element but that doesnt help.
Some event handler is getting called and i cannot find out which one (i have set breakpoints in all event handlers in the telerik.treeview.js but none are called when i click inside the textbox.
anybody have any idea?

Resources