第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

未為 SAPUI5 自定義控件定義 valueStateText

未為 SAPUI5 自定義控件定義 valueStateText

慕碼人2483693 2022-10-08 17:04:07
我通過擴展 sap.m.Input 創(chuàng)建了以下自定義控件,該控件允許用戶僅輸入數(shù)字。但是,當實際發(fā)生錯誤時,控制狀態(tài)會更改為帶有紅色邊框的錯誤,但 valueStateText 在具有焦點時不會顯示。如何獲取自定義控件的 valueStateText?它不應該從 sap.m.Input 繼承嗎?自定義控制代碼:sap.ui.define([    "sap/m/Input"], function (Control) {    "use strict";    return Control.extend("sample.control.NumericInput", {        metadata: {            properties: {},            aggregations: {},            events: {}        },        init: function () {            if (sap.ui.core.Control.prototype.onInit) {                sap.ui.core.Control.prototype.onInit.apply(this, arguments);            }            this.attachLiveChange(this.onLiveChange);        },        renderer: function (oRM, oControl) {            sap.m.InputRenderer.render(oRM, oControl);        },        onLiveChange: function (e) {            var _oInput = e.getSource();            var val = _oInput.getValue();            val = val.replace(/[^\d]/g, "");            _oInput.setValue(val);        }    });});XML 代碼:<hd:NumericInput value="{path:'payload>/MyNumber',type:'sap.ui.model.type.String',constraints:{minLength:1,maxLength:10}}" valueStateText="My Number must not be empty. Maximum 10 characters."/>
查看完整描述

2 回答

?
料青山看我應如是

TA貢獻1772條經驗 獲得超8個贊

在您的init覆蓋中,您需要調用init父控件的 (而不是 onInit sap.ui.core.Control)。(init的父sap.m.InputBase類sap.m.Input) 設置 valuestate 初始值和渲染,因此它丟失了所有代碼并且無法正常工作,就像您發(fā)現(xiàn)的那樣。


根據(jù)您的代碼查看此示例:


sap.ui.define([

    "sap/m/Input"

], function (Control) {

    "use strict";

  

    return Control.extend("sample.control.NumericInput", {

        metadata: {

            properties: {},

            aggregations: {},

            events: {}

        },

        init: function () {

            Control.prototype.init.apply(this, arguments);

            this.attachLiveChange(this.onLiveChange);

        },

        renderer: function (oRM, oControl) {

            sap.m.InputRenderer.render(oRM, oControl);

        },

        onLiveChange: function (e) {

            var _oInput = e.getSource();

            var val = _oInput.getValue();

            val = val.replace(/[^\d]/g, "");

            _oInput.setValue(val);

        }

    });

});



// Small model

const model = new sap.ui.model.json.JSONModel({

  MyNumber: "10000000000000000000",

});


// Create an example of the control (JS not XML but idea is the same)

const input = new sample.control.NumericInput({

  valueState: "Error",

  valueStateText:"My Number must not be empty. Maximum 10 characters.",

  value: {

    path:'/MyNumber',

    type:'sap.ui.model.type.String',

    constraints:{minLength:1,maxLength:10}

  }

});


input.setModel(model);

input.placeAt('content');

<!DOCTYPE html>

<html>

  <head>

    <meta charset="utf-8">

    <title>JS Bin</title>

    <script 

            src="https://openui5.hana.ondemand.com/resources/sap-ui-core.js" 

            id="sap-ui-bootstrap" 

            data-sap-ui-theme="sap_fiori_3" 

            data-sap-ui-xx-bindingSyntax="complex" 

            data-sap-ui-libs="sap.m"></script>

  </head>

  <body class="sapUiBody sapUiSizeCompact">

    <div id='content'></div>

  </body>

</html>


查看完整回答
反對 回復 2022-10-08
?
LEATH

TA貢獻1936條經驗 獲得超7個贊

你可以大大減少你的代碼


  Input.extend('NumericInput', {

    renderer: {

    },

    onAfterRendering: function () {

      if (Input.prototype.onAfterRendering) {

        Input.prototype.onAfterRendering.apply(this, arguments);

      }

      this.$().find("INPUT").each(function(i, input) {

        $(input).on("keypress keyup blur", function(event) {

            $(this).val($(this).val().replace(/[^\d].+/, ""));

            if ((event.which < 48 || event.which > 57)) {

                event.preventDefault();

            }

         });

      });

    },

  });

https://jsbin.com/muberid/1/edit?js,輸出


查看完整回答
反對 回復 2022-10-08
  • 2 回答
  • 0 關注
  • 86 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號