cancel
Showing results for 
Search instead for 
Did you mean: 

Uncaught TypeError: Cannot read property 'setValue' of undefined

rubens12
Participant
0 Kudos

I can't set a value in my input.

When I try do it the console shows error "Uncaught TypeError: Cannot read property 'setValue' of undefined"

The error is in the line "sap.ui.getCore().byId("InputValueHelp").setValue(oSelectedItem.getTitle());"

My Controller code is bellow

sap.ui.define([
		'jquery.sap.global',
		'sap/ui/core/Fragment',
		'sap/ui/core/mvc/Controller',
		'sap/ui/model/Filter',
		'sap/ui/model/json/JSONModel'
	], function(jQuery, Fragment, Controller, Filter, JSONModel) {
	"use strict";


	var CController = Controller.extend("sap.m.sample.InputStates.C", {
		
		onInit: function () {
			// set explored app's demo model on this sample
		
		},


	valueHelpRequest: function(oEvent) {


        var model = new sap.ui.model.json.JSONModel();
        var newurl = "http://services.odata.org/Northwind/Northwind.svc/Categories";
        model.loadData(newurl, null, false, "GET", false, false, null);
        // Handling of both confirm and cancel; clear the filter
        var handleClose = function(oEvent) {
          var oSelectedItem = oEvent.getParameter("selectedItem");
          if (oSelectedItem) {
          	 sap.ui.getCore().byId("InputValueHelp").setValue(oSelectedItem.getTitle());
            }
          oEvent.getSource().getBinding("items").filter([]);
        };
        // Create a SelectDialog and display it; bind to the same
        // model as for the suggested items
        if (!this._valueHelpSelectDialog) {
          this._valueHelpSelectDialog = new sap.m.SelectDialog("valueHelpSelectDialog", {
            title: "Categories",
            items: {
              path: "/value",
              template: new sap.m.StandardListItem({
                title: "{CategoryName}",
                active: true
              })
            },
            search: function(oEvent) {
              var sValue = oEvent.getParameter("value");
              var oFilter = new sap.ui.model.Filter(
                "CategoryName",
                sap.ui.model.FilterOperator.Contains, sValue
              );
              oEvent.getSource().getBinding("items").filter([oFilter]);
            },
            confirm: handleClose,
            cancel: handleClose
          });


          this._valueHelpSelectDialog.setModel(model);


        } else {
          this._valueHelpSelectDialog.setModel(model);
        }
        this._valueHelpSelectDialog.open();


      }
	});




	return CController;


});
View Entire Topic
junwu
Active Contributor

var that=this;

var handleClose =function(oEvent){

          var oSelectedItem = oEvent.getParameter("selectedItem");if(oSelectedItem){that.byId("InputValueHelp").setValue(oSelectedItem.getTitle());}
          oEvent.getSource().getBinding("items").filter([]);};
rubens12
Participant
0 Kudos

Now it's work.

I have another doubt,if I cosume a Odata service with username and password, where I put the password and the username in the method model.loadData()?

Thank you

junwu
Active Contributor
0 Kudos

please accept this as answer.thanks

rubens12
Participant
0 Kudos

Can you help me in my another post? https://answers.sap.com/questions/150202/method-modelloaddata.html

Thanks