admin管理员组

文章数量:1394149

I am creating an application enable user to dynamically add new label and input into form. But I have set the new input id and enabled is false dynamically added by user. But when I click edit button, enabled set to true. It does not work. My application cant read the input id that I added dynamically in form.

The following is my sample code.

Add new label and input into my current form

        var _oSF2 = this.getView().byId("Extension_Form");
        _oSF2.addContent(new sap.m.Label({
                text: "Classification"
            }));
        _oSF2.addContent(new sap.m.Input({
                  id : "idExtensionInput1",
                  text : "text",
                  enabled: false
            }));

Set enablement for new input to true

    handleEditPress: function () {
        this.getView().byId("idExtensionInput1").setEnabled(true);

    }

I am creating an application enable user to dynamically add new label and input into form. But I have set the new input id and enabled is false dynamically added by user. But when I click edit button, enabled set to true. It does not work. My application cant read the input id that I added dynamically in form.

The following is my sample code.

Add new label and input into my current form

        var _oSF2 = this.getView().byId("Extension_Form");
        _oSF2.addContent(new sap.m.Label({
                text: "Classification"
            }));
        _oSF2.addContent(new sap.m.Input({
                  id : "idExtensionInput1",
                  text : "text",
                  enabled: false
            }));

Set enablement for new input to true

    handleEditPress: function () {
        this.getView().byId("idExtensionInput1").setEnabled(true);

    }
Share Improve this question edited Nov 16, 2018 at 15:32 Jaro 1,7541 gold badge16 silver badges36 bronze badges asked Aug 28, 2018 at 3:31 Chan Yoong HonChan Yoong Hon 1,8227 gold badges37 silver badges73 bronze badges 2
  • did you look if your control has the ID via F12 Elements Tab? – Erch Commented Aug 28, 2018 at 5:17
  • Yes, it have ID with "idExtensionInput1-inner" – Chan Yoong Hon Commented Aug 28, 2018 at 6:20
Add a ment  | 

1 Answer 1

Reset to default 4

You've added the input to no view. In your case, you can only access the input with sap.ui.getCore().byId("idExtensionInput1") but the correct way is to use this.getView().createId() and add it to the right view.

    var _oSF2 = this.getView().byId("Extension_Form");
    _oSF2.addContent(new sap.m.Label({
            text: "Classification"
    }));
    <!-- language: lang-js -->

    _oSF2.addContent(new sap.m.Input({
        id : this.getView().createId("idExtensionInput1"), //Use createId() for this.getView()
        text : "text",
        enabled: false
    }));

    handleEditPress: function () {
       this.getView().byId("idExtensionInput1").setEnabled(true);
    }

One ment: The first parameter for new sap.m.Input is the id. Please write:

       _oSF2.addContent(new sap.m.Input(this.getView().createId("idExtensionInput1"), {
            text : "text",
            enabled: false
        }));

本文标签: javascriptSAPUI5 Form Add Label and Input dynamically and set ID for Input but not functionStack Overflow