cancel
Showing results for 
Search instead for 
Did you mean: 

Regarding Coding in Controller

Former Member
0 Kudos

Controller:

sap.ui.define([

  "sap/ui/core/mvc/Controller"

], function(Controller) {

  "use strict";

  return Controller.extend("test.controller.View1", {

  });

  onPress: function(){

     alert("hi");

  }

             

});

=============================

View:

<mvc:View controllerName="test.controller.View1" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m">

  <App>

  <pages>

  <Page title="{i18n>title}">

  <content>

     <Button

      id="id"

      busy="false"

      busyIndicatorDelay="1000"

      visible="true"

      fieldGroupIds="[]"

      text="Raghu"

      type="Default"

      width=""

      enabled="true"

      icon=""

      iconFirst="true"

      activeIcon=""

      iconDensityAware="true"

      textDirection="Inherit"

      validationSuccess=""

      validationError=""

      parseError=""

      formatError=""

      validateFieldGroup=""

      tap=""

      press= "onPress">

      <tooltip></tooltip><!-- sap.ui.core.TooltipBase -->

      <customData></customData><!-- sap.ui.core.CustomData -->

      <layoutData></layoutData><!-- sap.ui.core.LayoutData -->

      <dependents></dependents><!-- sap.ui.core.Control -->

     </Button>

  </content>

  </Page>

  </pages>

  </App>

</mvc:View>

I am creating Button with event press Event name is onPress

onPress: function(){

alert("Hi!! U Pressed Me!!");

}

My question, where should I write the onPress event code in the controller, where exactly I should insert it.

Regards,

Raghu

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

You need to write it as shown below

Controller:

sap.ui.define([

  "sap/ui/core/mvc/Controller"

], function(Controller) {

  "use strict";

 

  return Controller.extend("test.controller.View1", {

onPress: function(){

         console.log("Hi");

            }

   });

});

Former Member
0 Kudos

Thanks Sir, after many posts I got a straight forward answer. Yes, I tried it and I got the result, we need to pass the controller name in return function

Former Member
0 Kudos

Can you please mark this as Answered. Thanks

Former Member
0 Kudos

Please check it sir,

Sir! how to change the size and length of input box?

Regards,

Raghu

Former Member
0 Kudos

you property "width".

Former Member
0 Kudos

when using width property, input field shows beside the button, I want it below the button

Regards,

Raghu

Former Member
0 Kudos

You will have to use control sap.m.VBox

<VBox>

  <Input type="Text" value="{binding}"

  </Input>

  <Label text="Label for Input">

  </Label>

</VBox>