cancel
Showing results for 
Search instead for 
Did you mean: 

DS1.6 - M Mode - Dropdown Box - On Select Event Fired Twice

Former Member
0 Kudos

Hi All,

I am experiencing a problem in DS1.6 (SP0 and SP1) in M mode with the On Select event for the Dropdown Box.

When an item is selected in the drop down list the On Select event is fired - this is expected - but the very next click anywhere in the application fires the event a second time - this is not expected.

Steps to reproduce:

- Create a blank DS1.6 application in M mode.

- Add a single Dropdown Box component (anywhere).

- Add two or more items to the Dropdown Box (values are not important).

- Add the following code to the On Select event for the Dropdown Box: APPLICATION.alert("Hi");

- Run the application (locally will do).

- Select a new value in the Dropdown Box. The app says "Hi". Close the alert.

- Click anywhere on the app. The app says "Hi". Close the alert.

Is anyone else experiencing the same problem or am I doing something wrong?

PS: I have noted the above behaviour in the BI Mobile App and IE 11. I am unable to test with other browsers.

Regards, Pat

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Patrick Godwin,

I don't think this is an bug, actually SAP fires the same method for De-Select / Select / Un-Focus / Enter hit for sap.m library controls, if you will observe this in your case it will not only fires the OnSelect() twice (once for De-Select and and second time for Select of Items in Drop down Box) also it will fire when you select and hitting Enter or or leaves focus from control during dropbox item select.

For Reference :SAPUI5 Explored,Even though it does not belongs to the Design Studio but concept wise same.

Workaround and Solutions:

1. Create two global variable as below

prevValue : String Type

newValue : String Type

default value empty

2. Use conditional code for example explained below, and try to push all you logic in Global Script function, so it will be reusable and easy to develop and maintenance.

if(prevValue=="")

{

  //First Time Select, Default selected item changed

  //Set the new and pre value as same

  prevValue = DROPDOWN_1.getSelectedText();

  newValue = prevValue;

  //Continue with your script

  GLOBAL_SCRIPTS_1.DoWork();

}

else if(prevValue == DROPDOWN_1.getSelectedText())

{

  //De-Select / Focus Leave or Enter button pressed

  //Don't continue with your script leave empty this else if block

}

else

{

  newValue = DROPDOWN_1.getSelectedText();

  //Continue with your script

  GLOBAL_SCRIPTS_1.DoWork();

  //Reset the Privious value for next time select

  prevValue = newValue;

}

3. Do Work example code

APPLICATION.alert("Previous Value : "+prevValue + "\nNew Value : " +newValue);

Thanks

MustafaBensan
Active Contributor
0 Kudos

Hi S Kumar,

I am still inclined to think this is a bug either with the Design Studio Dropdown Box implementation or the underlying sap.m.Select control.  The Change event of the sap.m.Select control should only be triggered whenever there is a change of the selected value relative to the last time the event was triggered.  The API documentation states that:

"This event is fired when the value in the selection field is changed in combination with one of the following actions:

  • The focus leaves the selection field
  • The Enter key is pressed
  • The item is pressed"

So the change should be triggered in combination with one of the three cases listed above but only once.  If a Change event has been triggered by the combination of a value change with item press, then a subsequent Enter or Leave Focus should not re-trigger the Change event because technically the selected value has not changed.

Another consideration for comparison is that the Dropdown Box in the normal SAPUI5 mode (which is based on the UI5 commons control) behaves as expected without the need for workaround scripting, so the SAPUI5 M Mode dropdown at least is not consistent with this.

The scripting approach you've suggested is certainly a good workaround but I think such extra scripting should not really have to be implemented if the event processing worked consistently.

Regards,

Mustafa.

Former Member
0 Kudos

Hi Mustafa,

Thanks for accepting the work around, your idea is sounds good to capture events and call only once here we also need to consider its mobile library where Select / FocusOut / Touch / Enter is not available like PC, so behave differently and also in different mobile OS behaviour may change. Please find some points below.

>So the change should be triggered in combination with one of the three cases listed above but only once.


"Its like when Enter Key is pressed or Focus leaves, i think its calling only once and only for the the item selected its calling twice (one time for De-Select and second time foe Select)."

> If a Change event has been triggered by the combination of a value change with item press, then a subsequent Enter or Leave Focus should not re-trigger the Change event because technically the selected value has not changed.


"This can be another thread whether capturing the De-Select / Select / Enter / Un-Focus in the same method is good or is reliable or not. Or it can be delivered in Three different method may called OnDeSelect(), OnSelect(), OnEnterKey(), and OnFocusOut() respectively like in other Event Oriented programming language."



Please note also this is sap.m control specially designed for small hand hold devices like Mobile phones etc, Here we have to think where above mentioned events (different method for different events) are possible and doable and on the box in all mobile OS and architectures as well. In UI5 sap.m also there is mProperties object, i think there we can check whether its first call or second with if-else condition and can code accordingly.


Above code length can be reduced to:

if(prevValue=="" || prevValue != DROPDOWN_1.getSelectedText())

{

  //Get the selected value

  newValue = DROPDOWN_1.getSelectedText();

  //Continue with your script

  GLOBAL_SCRIPTS_1.DoWork();

  //Reset the Privious value for next time select

  prevValue = newValue;

}


Thanks

MustafaBensan
Active Contributor
0 Kudos

Hi Pat,

I have been able to replicate your issue on IE 11, Chrome 49 and Safari 9.  I'm inclined to think this is a bug so you may wish to raise an SAP Support Ticket for a resolution.

Regards,

Mustafa.