2016-11-28 17 views
0

sap.m.Inputのカスタム拡張を作成しました。 onAfterRenderingでは、私は次のようにjquery-maskmoneyを使用して使用して値をマスクする:拡張sap.m.Input:onAfterRenderingメソッドが機能しません

$('#'+this.getId()+'-inner').maskMoney({ thousands : '', decimal : '.' });' 

私はコンソールにマスクを適用すると、すべてが正常に動作します。

amountInputControl.setValue(data.amount); // Its is an instance of NumericInput 

エラー:

TypeError: Cannot read property 'val' of undefined 
    at sap.m.InputBase._getInputValue (InputBase.js:9) 
    at sap.m.InputBase.updateDomValue (InputBase.js:32) 
    at sap.m.InputBase.setValue (InputBase.js:34) 
    at sap.ui.controller.updateFieldsForReference //Here was executed operation setValue 

NumericInput.js

jQuery.sap.declare("control.customInputTypes.NumericInput"); 
      sap.ui.define(['jquery.sap.global', 'sap/m/Input'], 

       function(jQuery, BaseInput) { 
        "use strict"; 

        var commonControlInput = BaseInput.extend('control.customInputTypes.NumericInput', /** @lends sap.m.Input.prototype */ { 
         metadata: {}, 
         renderer : { 
          render : function(oRm, oControl) { 
           sap.m.InputRenderer.render(oRm, oControl); 
          } 
         } 
        }); 

     commonControlInput.prototype.onAfterRendering = function() { 
        $('#'+this.getId()+'-inner').maskMoney({ thousands : '', decimal : '.' }); 
       }; 

      return commonControlInput; 
    }, /* bExport= */ true); 

を私はsetValueのにしようとしているとき、私は しようとすると、しかしonAfterRendering方法でそれを追加し、私は若干の誤差が出ます私はInputBaseクラスに触れなかったので何が間違っているのだろうか?私はこのマスクを適用しない場合、すべて正常に動作します。 コントロールのonAfterRenderingメソッドでjQueryを使用できない場合がありますか?

+0

あなたはSAPUI5バージョンとjQuery-maskmoneyバージョンについて言及できますか?私はあなたのコードを試したが、何の問題に直面しなかった。 –

答えて

0

最初は、私はあなたがsap.m.MaskInputをチェックしたい場合があります取り払わが、私はそれが...正確に何をしたいとにかく

ないだと思う、私はあなたのコードに変更しますいくつかあります。ここでは、実行中ですjsbin example

<!DOCTYPE html> 
<html> 
    <head> 
     <meta charset="utf-8"> 
     <title>SAPUI5 single file template | nabisoft</title> 
     <script src="https://openui5.hana.ondemand.com/resources/sap-ui-core.js" 
      id="sap-ui-bootstrap" 
      data-sap-ui-theme="sap_bluecrystal" 
      data-sap-ui-libs="sap.m" 
      data-sap-ui-bindingSyntax="complex" 
      data-sap-ui-compatVersion="edge" 
      data-sap-ui-preload="async"></script> 
      <!-- use "sync" or change the code below if you have issues --> 

     <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-maskmoney/3.0.2/jquery.maskMoney.min.js"></script> 

     <!-- XMLView --> 
     <script id="myXmlView" type="ui5/xmlview"> 
      <mvc:View 
       controllerName="MyController" 
       xmlns="sap.m" 
       xmlns:core="sap.ui.core" 
       xmlns:mvc="sap.ui.core.mvc" 
       xmlns:cit="control.customInputTypes"> 

       <cit:NumericInput value="1219999234" /> 

      </mvc:View> 
     </script> 

     <script> 
      sap.ui.getCore().attachInit(function() { 
       "use strict"; 

       //### Custom Control ### 
       // remove the first parameter in "real" apps 
       sap.ui.define("control/customInputTypes/NumericInput",[ 
        "jquery.sap.global", 
        "sap/m/Input", 
        "sap/m/InputRenderer" 
       ], function(jQuery, Input, InputRenderer) { 
        "use strict"; 

        return Input.extend("control.customInputTypes.NumericInput", { 

         init : function() {       
          this.addEventDelegate({ 
          onAfterRendering : function(){ 
           var $input = jQuery("#"+this.getId()+"-inner"); 
           $input.maskMoney({ 
           thousands : ".", 
           decimal : "," 
           }).maskMoney("mask"); 
          }.bind(this) 
          }); 
         }, 

         renderer : InputRenderer 

        }); 
       }); 

       //### Controller ### 
       sap.ui.define([ 
        "sap/ui/core/mvc/Controller" 
       ], function (Controller) { 
        "use strict"; 

        return Controller.extend("MyController", { 
         onInit : function() { 

         } 
        }); 
       }); 

       //### THE APP: place the XMLView somewhere into DOM ### 
       sap.ui.xmlview({ 
        viewContent : jQuery("#myXmlView").html() 
       }).placeAt("content"); 

      }); 
     </script> 

    </head> 

    <body class="sapUiBody"> 
     <div id="content"></div> 
    </body> 
</html> 
+0

これは、initメソッドへのバインディングをonAfterRenderingの手助けとして動かしています。 我々はまだプラグインに問題がありました。私たちは」まさにこの1 https://github.com/plentz/jquery-maskmoney/issues/203 https://github.com/plentz/jquery-maskmoney を使用された https://github.com/BankFacil/vanilla-masker と今のところすべてが動作しています。 ありがとうございました – Remiwaw

関連する問題