cancel
Showing results for 
Search instead for 
Did you mean: 

sap.m.Select, aggregation without default value

Former Member
0 Kudos

When using a data aggregation on sap.m.Select, the first entry is always selected. Here's a link to the SDK's preview.

Example code from my app


new sap.m.Select("id-names", {

width: '100%'

}).bindAggregation("items", "data>/trip/names", new sap.ui.core.Item({

text: "{data>Name}"

}));

There is a parameter called selectedKey on the constructor to change this to another index. What I want is the select to be blank, because I want to force my users to make a choice, not blindly accept the first entry in the list.

I could force a blank entry in my aggregation data>/trip/names but that would pollute my list.

Is there a better way to achieve this?

Accepted Solutions (1)

Accepted Solutions (1)

saivellanki
Active Contributor
0 Kudos

Hi Jorg,

You can handle this in UI logic.

Declare an empty array -

var jData = {"text":"--Select--","key":""};

Now add this array at starting of your model -

sap.ui.getCore().getModel().getProperty("data>/trip/names").unshift(jData);


First entry in your model will be blank.


Update: Oops, I forgot to check this condition in your post, Sorry! - I could force a blank entry in my aggregation data>/trip/names but that would pollute my list.

The above logic is what I implemented, since we are not changing anything from the backend, It's just the model that associated with dropdown has been changed from UI. But, anyways it's a good question let's see if anyone can get solution for this.


Regards,

Sai Vellanki.

Message was edited by: Sai Vellanki

Answers (5)

Answers (5)

Former Member
0 Kudos

Hey everyone,

There's an open issue for this out on github: https://github.com/SAP/openui5/issues/409

In the meantime, I'll roll with your suggestion and add an item to my dataset.

former_member182862
Active Contributor
0 Kudos

I tried it out and it is kind of cumbersome

JS Bin - Collaborative JavaScript Debugging

santhu_gowdaz
Active Contributor
0 Kudos

First time only it's showing "--Select a trip--". After selecting any value,text will not be visible.using insert you added this text then it should be visible right?

former_member182862
Active Contributor
0 Kudos

Sorry, I do not understand your question. Really sorry.

Private_Member_15166
Active Contributor
0 Kudos

Just comment this one and you will get the solution.

var sel = new sap.m.Select({

  selectedKey: '{/selectedTrip}',

  autoAdjustWidth: true,

  items: {

    path: '/trips',

    template: new sap.ui.core.Item({

      key: '{Name}',

      text: '{Name}'

    })

  },

//  change: function() {

//    if (this.getFirstItem().getKey() === '') {

//      this.removeItem(0);

//    }

//  }

});

santhu_gowdaz
Active Contributor
0 Kudos

First time it's showing "--Select a trip--". After selecting any value Japan,China, the text "--Select a trip--" was gone from the dropdown.

santhu_gowdaz
Active Contributor
0 Kudos

Sorry Guys, My Mind is not working Thanks and

former_member182372
Active Contributor
0 Kudos

add a blank line to select (not to the model but to control), that's probably the best option for you.

santhu_gowdaz
Active Contributor
0 Kudos

Please elaborate the solution It will helpful for so many people including me.

former_member182372
Active Contributor
0 Kudos

covered it all: You can attach a blank item by addItem or insertItem method of the same.

Private_Member_15166
Active Contributor
0 Kudos

Hi,

You can attach a blank item by addItem or insertItem method of the same.

santhu_gowdaz
Active Contributor
0 Kudos

use combobox,

SAPUI5 Explored

Former Member
0 Kudos

This could work! Let me verify.

santhu_gowdaz
Active Contributor
0 Kudos

Most of the available properties in sap.m.select also be available in sap.m.combobox then again push 1 null value etc,.. why this much of headache. any how sap is providing sap.m.combobox to reduce our headache.

Former Member
0 Kudos

This has other problems, such as not being able to put your finger on the entire comboboox. combobox accepts manually entered text, which is not the intention.

Former Member
0 Kudos

This is about a framework that does what I want, not about me fitting my requirements into the technicalities of the framework.

I can type in the combobox. I can't tap the combobox and get the dropdown, I need the tap the arrow. I don't want that. My app runs on a tablet that's used by people with big fingers