Access a widget property in the script

  • Leonid Gauss
        Has successfully completed the online course Intermediate (200)
        Has successfully completed the online course Basics (100)
      1 year ago #39399

      I want to check in a script in a condition if a CheckBox is
      is checked, but I don’t know how to access properties of a widget with JavaScript code. A widget inside an app can be accessed like this: sap.ui.getCore().byId(“Screenname–WidgetID”) . after the dot you can select a method, but how do I access a widget property?

      Thanks in advance

      Greetings Leonid

      Moritz Strauss
          Has successfully completed the online course Introduction
          Has successfully completed the online course Intermediate (200)
          Has successfully completed the online course Advanced (300)
          Has successfully completed the online course Basics (100)
          Has successfully completed the Intermediate Certification
        1 year ago #39424
        Up
        0
        Down
        ::

        Hello Leonid,

        with sap.ui.getCore().byId(“Screenname–WidgetID”).mProperties you can see all available properties of the widget.
        With sap.ui.getCore().byId(“Screenname–WidgetID”).getProperty(propertyName) you can get the value of a specific property.
        This is the generic way, but each property has a specific getter and setter.

        For your example of a CheckBox you could do this:
        sap.ui.getCore().byId(“Screenname–WidgetID”).getProperty(“selected”) which will return either true or false depending on whether or not the CheckBox is currently selected.
        We recommend using the selected-specific getter .getSelected()

        Please follow the official OpenUI5 documentation for more information on the available properties and methods: https://openui5.hana.ondemand.com/api/sap.m.CheckBox

        Leonid Gauss
            Has successfully completed the online course Intermediate (200)
            Has successfully completed the online course Basics (100)
          1 year ago #39428
          Up
          0
          Down
          ::

          Thank You Moritz!

        Viewing 3 posts - 1 through 3 (of 3 total)

        You must be logged in to reply to this topic.