cancel
Showing results for 
Search instead for 
Did you mean: 

Hide button on the event.

Former Member
0 Kudos

Hello!

Please help understand the problem.

I created a view.

Inside view is page.


<mvc:View

    controllerName="sap.ui.....forms.controller.FormGoals"

    height="100%"

    xmlns="sap.m"

  xmlns:mvc="sap.ui.core.mvc"

  xmlns:core="sap.ui.core"

  xmlns:l="sap.ui.layout"

  xmlns:f="sap.ui.layout.form">

   

  <Page

  id="formgoals_page"   

     showHeader="true"

  title="First Page"

  enableScrolling="true"

  class="gsjPageStyle">

     <customHeader>

  <Toolbar>

  <ToolbarSpacer/>

  <Title text="{main_data>/output/empl_fio}" />

  <ToolbarSpacer/>

  </Toolbar>

  </customHeader>

    

  <content>  

  <l:VerticalLayout width="100%">

  <!--

  <Label text="{main_data>/output/empl_fio}"/>

  <Label t

  ..........................................

  <footer id="formgoals_footer">

  </footer>

  </Page>

</mvc:View>

Footer page is created in the fragment.

In footer has several buttons. When I click one of them, the others have to hide.


sap.ui.jsfragment("sap.ui.x5.forms.view.FormGoals_Footer_Toolbar", {

  createContent: function(oController) {

  var o_toolbar;

  var button_save;

  var button_cancel;

  var button_comments;

  var o_dfc = oController.getOwnerComponent().main_data; //Sturcture

  var o_settings_data = oController.getOwnerComponent().settings_data; //Sturcture

  button_edit = new sap.m.Button("btnEdit", {

  text: ("Edit"),

  visible: true

  press: [oController.handleEditPres, oController]

  });

  button_cancel = new sap.m.Button("btnCancel", {

  text: ("Cancel"),

  visible: true

  press: [oController.handleCancelPress, oController]

  });

  button_comments = new sap.m.Button("btnComment", {

  text: ("Comment"),

  visible: true,

  press: [oController.handleShowComments, oController]

  });

  o_toolbar = new sap.m.Toolbar({

  content: [button_comments,

           new sap.m.ToolbarSpacer(),

           button_save,

           button_cancel]

  });

  return o_toolbar;

  }

});

To implement this function, I get the view from the controller.


sap.ui.define([

  'jquery.sap.global',

  'sap/m/Dialog',

  'sap/m/MessageToast',

  'sap/ui/core/Fragment',

  'sap/ui/core/mvc/Controller',

  'sap/ui/model/json/JSONModel',

  ], function(jQuery, Dialog, MessageToast, Fragment, Controller, JSONModel) {

  "use strict";

  var sResult = '';

  var FormGoalsController = Controller.extend("sap.ui......forms.controller.FormGoals", {

  onInit: function (oEvent) {

  var main_page;

  main_page = this.getView().byId('formgoals_page');

  main_page.setFooter(this._getFormFragment("FormGoals_Footer_Toolbar"));

  },

  //....

  _formFragments: {},

  _getFormFragment : function (sFragmentName) {

  var oFormFragment = this._formFragments[sFragmentName];

  if (oFormFragment) {

  return oFormFragment;

  }

  oFormFragment = sap.ui.jsfragment("sap.ui......forms.view." + sFragmentName, this);

  return this._formFragments[sFragmentName] = oFormFragment;

  },

  //....

  handleEditPress: function(){

  var o_view = this.getView();

  o_view.byId("btnComment").setVisible(false); //ERROR!!!

  o_view.byId("btnCancel").setVisible(false);

  var o_view_mono_table = o_view.byId("mono_table_main");

  o_view_mono_table.getController()._showFormFragment("MonoTable_Edit");

  o_settings_mod.setProperty("/edit_tables", !edit_stat);

  o_settings_mod.refresh(true);

  },

  //....

  return FormGoalsController;

});

And I try to get the ID of the button to hide them. But I get this error:

Uncaught TypeError: Cannot read property 'setVisible' of undefined

Explain please, what am I doing wrong?

Accepted Solutions (1)

Accepted Solutions (1)

karthikarjun
Active Contributor
0 Kudos

Hi Sergey,

sap.ui.getCore().byId("btnComment").setVisible(false);

Thanks,

Karthik A

Answers (4)

Answers (4)

Former Member
0 Kudos

Alternively you can bind the visibility property of the buttons to a property in a model. If you want to change the visibility, just change the value in the model.

Former Member
0 Kudos

Hi! I tried this method, but I could not. I still do not understand why. Will continue to seek a solution.

SergioG_TX
Active Contributor
0 Kudos

o_view.byId("btnComment").setVisible(false);

Former Member
0 Kudos

Hi,

Use

o_view.byId("btnComment").style.visibility = 'hidden';

and


o_view.byId("btnComment").style.visibility = 'visible';

Former Member
0 Kudos

Hi,

     Weather button is hide successfully?

Former Member
0 Kudos

Hi! Unfortunately no, this method is not working. But it works the way:

'sap.ui.getCore (). ById ("btnComment"). SetVisible (false);'.

I will use it ...and I will understand further.

former_member182372
Active Contributor
0 Kudos

when you create a fragment, first param is frgament id

oFormFragment = sap.ui.jsfragment("FRAGMENT_ID", forms.view." + sFragmentName, this); 



to get controle out of that fragment you call


sap.ui.getCore().byId( "FRAGMENT_ID--btnComment")