cancel
Showing results for 
Search instead for 
Did you mean: 

How to change control from other control in mvc

Former Member
0 Kudos

Hi,

I've MVC app with  text field and I want that when the user enter some text on it it will change the drop down selected value,

How should I do that ?

Example will be very helpful

This is the text field and for example when you type aaa I want that the drop down will have aaa selected

for example the drop down contain aaa bbb ccc etc

var tF = new sap.ui.commons.TextField({

  liveChange: [oController.onChange, oController]

  });

I saw the last example here but its not helpful since this example is not using  MVC

DropdownBox - SAPUI5 Demo Kit

I need somehow in the live change of the text field do the drop down logic to change the selected value

Accepted Solutions (1)

Accepted Solutions (1)

former_member182862
Active Contributor
0 Kudos

Hi Stephane

Would this help?

Sample

-D

Former Member
0 Kudos

Hi Dennis,

Yes this is helping but I need the exact same functionality in MVC ,

the logic should handeld in the controller

in the text field i use the following


var tF = new sap.ui.commons.TextField({

  liveChange: [oController.onChange, oController]

  });

Thanks!!

former_member182862
Active Contributor
0 Kudos

take 2 🙂

Sample

-D

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi All,

Any way how to do that right ?

Thanks

udaykumar_kanike
Active Contributor
0 Kudos

Stephane,

The example that I provided is with JSON model. You have to implement same logic for Odata model in your case except that you have to collect your entity set into an array and filter the values based on input values.

var oHelpModel = new sap.ui.model.json.JSONModel();

  if (DATABINDING) {

    console.log("Gateway Databinding for Value Help");

// http:///sap/opu/odata/sap//MaterialSet?$select=Matnr,Descr&$format=json

      var helpURL = "http:///sap/opu/odata/sap//MaterialSet";

      var queryString =”$select=Matnr,Descr&$format=json”;

      oHelpModel.loadData( helpURL, queryString, false);

  }

  else {

      console.log("Local Databinding for Value Help");

      oHelpData =

          {"d":{"results":[

                        {"Matnr":"4711","Descr":"Snowboard"},

                        {"Matnr":"4712","Descr":"Mountain Ski"},

                        {"Matnr":"4713","Descr":"Backcountry Ski"},

                        {"Matnr":"4714","Descr":"Freeride Ski"},

                        {"Matnr":"2011001","Descr":"Ski Boots"},

                        {"Matnr":"2011002","Descr":"Ski Poles"},

                        {"Matnr":"2011003","Descr":"Rucksack"},

                        {"Matnr":"5550001","Descr":"Ski Googles"},

                        {"Matnr":"5550002","Descr":"Ski Helmet"},

                        {"Matnr":"5550007","Descr":"GPS Unit"}

      ]}};

      oHelpModel.setData(oHelpData);

  }

           

  oHelpTable.setModel(oHelpModel);

  oHelpTable.bindAggregation("rows", "/d/results");

Hope it helps.

Regards

Uday

Former Member
0 Kudos

HI Again,

any idea how to solve it?

example will be very helpful

Thanks!

kedarT
Active Contributor
0 Kudos

Hi Stephane,

Hope this example helps. which used MVC:

JS Bin - Collaborative JavaScript Debugging

udaykumar_kanike
Active Contributor
0 Kudos

Stephane,

Are you referring to Value help field ?

Please check following links.

JsDoc Report - SAP UI development Toolkit for HTML5 - API Reference - sap.ui.commons.ValueHelpField

Regards

Uday

Former Member
0 Kudos

Thanks but this is not what I mean...

Former Member
0 Kudos

Something like this.

Edit fiddle - JSFiddle

You can give some values in textfield like aaa,bbb,ccc, etc and see the corresponding change in dropdown

Former Member
0 Kudos

HI indrajith,

This is close but not exactly what I mean,its working in your example (and in the example which I add in the first post )but sinceI use MVC and the text field is like following

var tF = new sap.ui.commons.TextField({

  liveChange: [oController.onChange, oController]

  });

I need somehow to delegate the functionality to the controller i.e. when user type text in the liveChange event

liveChange: [oController.onChange, oController]


I need to call in the controller also to some event in the DDB to change the selected value...


This is the big question here,how to do that ?


Regards,

Stephen

kedarT
Active Contributor
0 Kudos
Former Member
0 Kudos

Hi Kedar

This is not what I meant ...:)

you need to have two controls

1.text field

2.drop down box

when you type in the field aaa the DDB should change the selected key .

the text  field is using the livechange event and when you type on something there the liveChange event will call to the DDB some event and change the selected key

the drop down box should somehow  listen to the livechange event in the text field...

its not that simple since the text field is implemented like following when the event logic is handeld in the controller....

var tF = new sap.ui.commons.TextField({

  liveChange: [oController.onChange, oController]

  });

Thanks!

kedarT
Active Contributor
0 Kudos

Hi Stephane,

Hope this example works - JS Bin - Collaborative JavaScript Debugging</title> <link rel="alternate" type=&q...

In input field put in value 1 and you will see values associated with Test 1 from the JSON Model.

Former Member
0 Kudos

Thanks keder,

closer but not the answer I see that this is works but you handle the changes inline like following

liveChange: function(e){                        

                              oFilter = new sap.ui.model.Filter('Test',sap.ui.model.FilterOperator.EQ,e.getParameter("value"));

                              oTestTxt.bindAggregation("items","/Data",oItem,null,oFilter);

                              }});

here you call to oTestTxt but as my previos post this live change have the given code which call to the controller with the method name(handle method and this) and since I use mvc (which is the way to go...)this raise some problem,

  liveChange: [oController.onChange, oController]

any idea how to solve it?

kedarT
Active Contributor
0 Kudos

Here it is:

In you view in Input you would define something like this:

var oText = new sap.m.Input({description:'Enter test value',

                             liveChange: function(e){                        

                                  oController.handlelivechange(e)

                              }});

In your Controller:

handlelivechnage: function(e){

here get the instance of dropdown box and its related item using sap.ui.getCore().byId("id")

and then change the aggregation binding.

};

Hope this helps.

Former Member
0 Kudos

Hi KEdar,

I cannot use the get core API sap.ui.getCore().byId("id")) since Im not using ID and our model is complicated ...there is other way to do that ?