cancel
Showing results for 
Search instead for 
Did you mean: 

CheckBox controlling hidden/visible fields in UI5

rodrigo_esteves
Advisor
Advisor
2,271

Hello guys!
I'm quite new in SAPUI5 development, and I'm trying to do a simple show and hide feature on my UI5 CRUD.

I believe this fairly simple thing to do, but maybe I'm calling the function how it is supposed to.
Here's how I'm trying to do it:

On the View:

--------------------------------------------------------------------------------------------------------------

// the check box

  var projectExtendedCheckBox = new sap.m.CheckBox(this.createId("extended-checkbox"),{

     selected :  false,

            enabled :  true,

            select : $.proxy(oController.handleHide)()

     

  });

//the fields and labels

var  projectCurrencyInput = new sap.m.Input(this.createId("currency-input"), {

     value: "EUR",

     visible:false

  });

  var  projectCurrencyInputLabel = new sap.m.Label(this.createId("currency-label"),{

  text: "Currency",

  labelFor: projectCurrencyInput.getId(),

  visible:false

  });

On the Controller:

--------------------------------------------------------------------------------------------------------------

//the function

handleHide : function(oEvent){

    

        var costLbl = this.oView().byId("cost-input-label");

        var checkBox = this.getView().byId("extended-checkbox");

         if(checkBox.getSelected()){

             costLbl.setVisible(true);

         }

      

    },

Accepted Solutions (0)

Answers (1)

Answers (1)

scott_stefanich
Active Participant
0 Kudos

Hello Rodrigo,

Here is a JS Bin sample which sets Label and Input control visibility using a CheckBox.


In creating the sample, I did notice your handleHide function gets id "cost-input-label" instead of id "currency-input".


Regards,

Scott

rodrigo_esteves
Advisor
Advisor
0 Kudos

Thanks Scott!