2017-06-20 39 views
1

我正在使用dijit.form.currencytextbox并希望允许负值。当我给值'-0.1'我得到的错误:使dijit.form.currencytextbox接受小数点后一位的负值

“输入的值无效”

当我给值'-0.10'值被接受为有效。

如何使'-0.1'成为有效值。 我曾尝试添加contraints-places:2以使输入的值在小数点后转换为两位数,但没有任何区别。 '0.1'自动格式化为'$0.10'并被接受为有效输入。

<input type="text" id="amountTextBox" data-field="amount" maxlength="10" 
     required="required" data-dojo-type="dijit/form/CurrencyTextBox" 
     value="0" data-dojo-props="constraints:{min:-9999999.99,max:9999999.99,places:2}, 
     currency:'USD', trim: true, intermediateChanges: true" /> 
+0

你正在使用哪种版本的dojo? –

回答

0

我认为这是由于道场版本问题

请你的项目设置为较新的版本,它应该工作

看到这个工作Fiddle whcich用途道场1.12

另见工作代码段:

require(["dijit/form/CurrencyTextBox", "dijit/form/Button", "dojo/on", 
 
    "dojo/domReady!" 
 
], function(CurrencyTextBox, Button, On) { 
 
    var fp = new CurrencyTextBox({ 
 
    currency: 'USD', 
 

 
    value: -0.1, 
 
    constraints: { 
 
     places: 2 
 
    } 
 
    }, 'currency'); 
 

 
    var btn = new Button({}, "btn"); 
 

 

 
    console.log(fp); 
 
    fp.startup(); 
 

 
    On(btn, "click", function(e) { 
 
    console.log(fp.get("value")) 
 
    alert(fp.get("value")); 
 
    }); 
 
});
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/dojo/1.12.1/dijit/themes/claro/claro.css" /> 
 

 

 

 
<script src="//ajax.googleapis.com/ajax/libs/dojo/1.12.1/dojo/dojo.js"></script> 
 

 
<div id='currency'></div> 
 
<br /><br /> 
 
<body class="claro"> 
 
    <div id='btn'> 
 
    Alert value 
 
    </div> 
 
</body>

+0

感谢@bRIMO更新至最新软件包解决了此问题。 – user1579234

+0

不客气@ user1579234,所以请认为标记答案已解决✓(留下答案):)可能会帮助其他人 –

+0

我没有足够的声望点来做到这一点。当我得到足够的分数时,我会这样做。 – user1579234

相关问题