Skip to Content
avatar image
Former Member

Hide button on the event.

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?

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

5 Answers

  • Best Answer
    Oct 16, 2015 at 06:57 AM

    Hi Sergey,

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

    Thanks,

    Karthik A

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 15, 2015 at 06:13 PM

    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")

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 15, 2015 at 06:13 PM

    Hi,

    Use

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

    and


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

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      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.

  • avatar image
    Former Member
    Oct 16, 2015 at 05:47 AM

    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.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

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

  • Oct 15, 2015 at 06:17 PM

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

    Add comment
    10|10000 characters needed characters exceeded