简体   繁体   English

根据SAPUI5中的复选框标志激活输入字段

[英]Activating an input field based on checkbox flag in SAPUI5

I am trying to activate an input field based on the checkbox flag. 我试图基于复选框标志激活输入字段。 The input field is not getting activated. 输入字段未激活。 Please help. 请帮忙。 Below are the snippets from the view and the component. 以下是该视图和组件的片段。

View------------------------------------------ 视图 - - - - - - - - - - - - - - - - - - - - -

<mvc1:View
   controllerName="sap.ui.demo.wt.controller.App"
   xmlns="sap.m"
   xmlns:mvc1="sap.ui.core.mvc1">

<CheckBox id="ch1" text="Test" selected="false" select ="checkDone" enabled="true" />

<Input  id="i1" enabled="false"></Input>

</mvc1:View>

Controller--------------------------------------- 控制器---------------------------------------

sap.ui.define([
                   "sap/ui/core/mvc/Controller"
                ], function (Controller) {
                   "use strict";
                   return Controller.extend("sap.ui.demo.wt.controller.App",{
                       checkDone: function (oEvent) {
                           var check = oEvent.getParameter("selected");
                            if (check === true){
                             sap.m.Input({id:"i1",
                                enabled:"true",
                                label: "Amount",
                                textAlign: sap.ui.core.TextAlign.Right,
                                value: "INR"
                             });
                           }else {
                                return "";
                           }
                        }
                   }); 
                });

You can bind the enbaled property from the input field to the model value of the checkbox. 您可以将enbaled属性从输入字段绑定到复选框的模型值。 Then if you check the box it should automatically en-/disable the input field. 然后,如果选中此框,则应自动启用/禁用输入字段。

Something like this: 像这样:

<CheckBox id="ch1" text="Test" selected="false" select ="checkDone" value="{someModel>/enabledValue}" enabled="true" />

<Input  id="i1" enabled="{someModel>/enabledValue}"></Input>
             checkDone: function (oEvent) {
                 var check = oEvent.getParameter("selected");
                  if (check){
                   this.getView().byId("i1").setEnabled(true);
                 }else{
                   this.getView().byId("i1").setEnabled(false);
                 }
              }

Check with the above code 检查上面的代码

For place holder inside input 用于内部输入的占位符

This is not the preferred way but... 这不是首选方法,但是...

<Input  id="i1" enabled="false" class="placeholder"></Input>

onAfterRendering : function(){
   $(".placeholder .sapMInputBaseInner").attr("placeholder", "Your placeholder Text");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM