cancel
Showing results for 
Search instead for 
Did you mean: 

Read data from input i.e.,sap.m.Input

Former Member
0 Kudos

Hi,

      I am trying to develop a simple mobile app that involves sap.m.input .I have gone through API references for the same but there is no api for reading data from input. My code is as follows :

sap.ui.jsview("myfirstmobile.MobileView", {

      getControllerName : function() {

         return "myfirstmobile.MobileView";

      },

      createContent : function(oController) {

   

                this.setHeight("100%");

               var flexbox=new sap.m.FlexBox({direction:"Column",height:"150px"});

               flexbox.addItem( new sap.m.Input("un",{placeholder:"Enter UserName"}));

               flexbox.addItem( new sap.m.Input("pass",{type:sap.m.InputType.Password,placeholder:"Enter Password"}));

               flexbox.addItem( new sap.m.Button('login',{text:"Log In",

                                                               

                                                                press:[oController.buttonClicked]}));

   

               flexbox.setAlignItems("Center");

               flexbox.setJustifyContent("Center");

  

              

     var page1 =new sap.m.Page("page",{

                  title: "LOG IN",

                  icon: "http://www.sap.com/global/ui/images/global/sap-logo.png",

                  content:flexbox,

          

         });

       return page1;

         

      }

});

   Could you please tell me how to read data from input field in mobile application i.e.,username .

Accepted Solutions (1)

Accepted Solutions (1)

former_member104694
Participant
0 Kudos

Hi Vijaykumar,

You can try something like this...

oInput = sap.ui.getCore().byId("un");

sValue = oInput.getValue();

Here is the link to the documentation

Cheers,

Ian

Former Member
0 Kudos

Read input value...

var inp = new sap.m.Input({text : "text"});

inp.getValue(); // return the current value

Regards,

Ajain

Former Member
0 Kudos

Hi guys,

  I have tried these two methods its not working.My code is

sap.ui.jsview("myfirstmobile.MobileView", {

      getControllerName : function() {

         return "myfirstmobile.MobileView";

      },

      createContent : function(oController) {

   

                this.setHeight("100%");

               var flexbox=new sap.m.FlexBox({direction:"Column",height:"150px"});

               //var un=

               flexbox.addItem(new sap.m.Input("un",{placeholder:"Enter UserName"}));

               var un=sap.ui.getCore().byId("un");

               var unV=un.getValue();

               flexbox.addItem( new sap.m.Input("pass",{type:sap.m.InputType.Password,placeholder:"Enter Password"}));

               flexbox.addItem( new sap.m.Button('login',{text:"Log In",press:function(){alert(unV);}}));

                         //oController.buttonClicked}));

               flexbox.setAlignItems("Center");

               flexbox.setJustifyContent("Center");

      var page1 =new sap.m.Page("page",{

                  title: "LOG IN",

                  icon: "http://www.sap.com/global/ui/images/global/sap-logo.png",

                  content:[flexbox]

          

         });

       return page1;

         

      }

});

In alert box its showing blank even if I give some value in my user name field.

Regards,

Vijay.

former_member104694
Participant
0 Kudos

Hi Vijay,

Move the following lines of code inside your button press event handler...

var un=sap.ui.getCore().byId("un"); 

var unV=un.getValue();

Currently you're calling getValue directly in createContent which is before it has any value

So it would look something like this...

flexbox.addItem( new sap.m.Button('login',{text:"Log In",press:function(){    

     var un=sap.ui.getCore().byId("un"); 

     var unV=un.getValue();

     alert(unV);

}}));

Regards,

Ian

Former Member
0 Kudos

JSBin Reference http://jsbin.com/ulifun/1/edit ... Check the output on the console...  Only after submitting you would get the current value....... 

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

 

  Thanks guys its working now.

   regards,

   Vijay.