2016-09-12 16 views
0

私はYii2フォーム入力で入力マスクを使用しようとしています。ここに私のコードは次のとおりです。inputmaskコードの次の行に問題にjqueryを使用してカスタムエイリアス入力マスクを適用するにはどうすればよいですか?

jQuery('selector').inputmask(IDR) 
jQuery('selector').inputmask("IDR") 
jQuery('selector').inputmask(eval(IDR)) 
jQuery('selector').inputmask({'mask':'IDR'}) 
jQuery('selector').inputmask({'alias':'IDR'}) 

クロームデバッガポイント:次の

var IDR={"alias":"numeric","prefix":"Rp","digits":0,"digitsOptional":false,"decimalProtect":true,"groupSeparator":",","radixPoint":".","radixFocus":true,"autoGroup":true,"autoUnmask":true,"removeMaskOnSubmit":true}; 
Inputmask.extendAliases({"IDR": {"alias":"numeric","prefix":"Rp","digits":0,"digitsOptional":false,"decimalProtect":true,"groupSeparator":",","radixPoint":".","radixFocus":true,"autoGroup":true,"autoUnmask":true,"removeMaskOnSubmit":true} }); 

ALLはjquery.inputmask.bundle.js上のエラー捕捉されないでSyntaxErrorを生成します:私はjquery.inputmask 3.x.From私の理解のドキュメントにエイリアスのプロパティを変更するための好ましい方法を見てきました

42: dataoptions = JSON.parse("{" + attrOptions + "}")), dataoptions) { 

答えて

1

継承する新しいエイリアスを作成することですsをデフォルトのエイリアス定義から削除します。

Inputmask.extendAliases({ 
     'numeric': { 
     "prefix":"Rp", 
     "digits":0, 
     "digitsOptional":false, 
     "decimalProtect":true, 
     "groupSeparator":",", 
     "radixPoint":".", 
     "radixFocus":true, 
     "autoGroup":true, 
     "autoUnmask":true, 
     "removeMaskOnSubmit":true 
     } 
    }); 

Inputmask.extendAliases({ 
    'IDR': { 
     alias: "numeric", //it inherits all the properties of numeric  
     "prefix":"Rpoverrided"//overrided the prefix property 
     } 
}); 

今働いフィドルが、私は私でこれをテストしている

Click to see the fiddle

以下の通りである。この

jQuery('selector').inputmask("IDR") 

のようなあなたのセレクタに入力マスクを適用クロムのブラウザで動作していることが判明しました。 data-inputmask属性がjQuery('selector').inputmask("IDR")コマンドの前に評価されますので、<input data-inputmask="IDR">を使用して 避けてください:エラー捕捉されないでSyntaxErrorを避けるために

。これにより、JSONparseエラー(https://github.com/RobinHerbots/Inputmask)が発生します。

data-inputmask attribute You can also apply an inputmask by using the data-inputmask attribute. In the attribute you specify the options wanted for the inputmask. This gets parsed with $.parseJSON (for the moment), so be sure to use a well-formed json-string without the {}.

+0

ありがとうございました。私はChromeのコンソールでこれを試したが、うまくいかなかった。この問題は、inputmask( "IDR")コマンドで起こっているようです。 jquery.inputmask.bundle.jsファイルがエラーをスローしている '{' + "IDR" + '}'を評価しようとしています。クレイジーなことは、私はちょうど作曲家からの更新をして、このエラーが起こったことです。それまでは大丈夫だった。 – zDaniels

関連する問題