SAPUI 5 add Button Press Event - button

I would like to know how we can write buttion press event in controller.
i.e. if the condition is satisfied, button is pressed.
this.getView().byId("idHeadBtn").press

I hope that I understand you correctly. You want to add a button handling for a particular button right? If so, you could do this:
var btn = this.getView().byId("idHeadBtn"); //or sap.ui.getCore().byId("idHeadBtn");
btn.attachPress(/*pressHandler*/);
For more information you could double check it: https://ui5.sap.com/#/api/sap.m.Button/methods/attachPress

Related

Hiding text in a button

I have a certain set of buttons registered so that they can be executed using letters in a keyboard or by mouse click. But I want to hide the text in the button from the user so that it looks more natural.
Heres part of the code:
ToggleButton btn1 = new ToggleButton("");
btn1.setMnemonicParsing(true); // instruction to parse mnemonic
btn1.setText("_7");
Now instead of the button showing a 7 in the middle I want it to be hidden but still function the same. I have a feeling it has something to do with the setVisible() method but I'm not sure how to use it for just the text inside the button instead of the entire button itself.
Most probably you can't do both at the same time. If you want to trigger the button using MneomonicParsing, then you have set the text and it will be visible in the button.
Why don't you use a onKeyPressed method of the container of those buttons instead? Then you don't have to set any text on the button. Like this:
container.setOnKeyPressed(k->{
switch(k.getCode()){
case NUMPAD7:
case DIGIT7: btn1.fire();
break;
//implement other cases
}
});

No event getting generated on button click in MFC

I have a dialog based application. I have one static text control and a button on this, both of which I have made invisible in the beginning. I want to show both the controls on reaching a certain condition. When I click this button, again I want to make both the controls invisible.
However, I am able to show and hide the control and also captured the button click event like this:
ON_BN_CLICKED(IDC_MY_BUTTON, &MyDlg::OnBnClickedMyButton)
and defined OnBnClickedMyButton().
But when I press the button, it is not pressed and the event is also not generated.
Any suggestions?
First check if the IDC_MY_BUTTON exists and is valid.
Remember to add DECLARE_MESSAGE_MAP() at the header file.
Also check at the BEGIN_MESSAGE_MAP(MyClass,MyParentClass) if the class
and the parent class you write are right.
I hope this helps.
I think the IDC_MY_BUTTON maybe is invalid or other control has the same ID.
Well, finally I have come to know that though the button was visible but on clicking it was not taking control, hence I used BringWindowToTop() to draw it on top. Now it is being clicked and OnBnClickedMyButton() is also being called.
But now the issue is that after calling BringWindowToTop() the button is not shown. It is shown only when I take the mouse pointer on it. Not able to understand what is the issue.

How to set the old value which was selected earlier, after a value change event fired

I am facing a problem like I have one Vaadin ComboBox with preselected value.I am changing the value from the ComboBox to another value,then ValueChangeEvent is fired.Inside the valueChange method I have written something to show a Popup Window which has Cancel and Ok button.Upon clicking on OK button of Popup Window I am going with the changed value of the ComboBox but upon clicking on Cancel button I just want to have the old value which was there before value change event fired.
Could anyone please help me out from the above issue?
Thanks in advance.
Maybe you can save whatever SelectedItem the combobox has when the event is fired, and if the user pressed cancel, you reset it to this stored item.
Before the click, how do you know what is selected in the click? Of course, you need to store the current selection somewhere. Lets call it currentSelectedValue (it could be NULL in the begining)
On click, you have a new selection, lets call it newSelectedValue
Now, if you do not want to go with this newSelectedValue, simply do this:
combo.setValue(currentSelectedValue);

flex button event handler

I have some buttons in a BorderContainer and I would like to execute the attached event when the user click on the buttons. But, the parent has a click event too.
I would like to execute the action A when the user click on the button A, the action B with the button B and the action C if the user click on the background.
Actually, if I add the eventHandler to the bordercontainer, the buttons don't work anymore. No mouse cursor, no mousehover effect, and if you click on it, it's the action C which is launched.
My bordercontainer:
useHandCursor = true;
mouseChildren = false;
buttonMode = true;
In both buttons and bordercontainer I use the MouseEvent.Click event and both call the same function "click" which will execute different actions depending the properties of the event.target.
My bad. Thank to Timofei.
Both the bordercontainer and the click function were wrong.
In the bordercontainer, mouseChildren had to be set at true, which will let the children get the event too.
And in my click function, using event.target was a bad idea. It tried to get the properties from the bordercontainreskin. I had to use event.currentTarget instead. Finally I added a event.stopPropagation() to prevent the bordercontainer to catch the event too when the user click on a button. And now, everything is working well now.
Thank you

replace button label

In actionscript, when I click a button I would like the label to replace from "add to list" to "added" without override with super method.
Is this even possible to change label in repeater?
You shouldn't have to override with a super method, though this is a decent way to do it. I would have the logic work something like this:
write a custom component that contains the button.
put the button in the repeater
on button click, tell the array to add an item to it, and listen for "itemAdded" on the arrayCollection class.
when you hear "itemAdded" inside the button container class, check to see if it is the item you added. If so, change your button's label to "Added" through button.label = "Added".
I think this should work just fine - best of luck.

Resources