Dojo: how to remove comma from value

怎甘沉沦 提交于 2019-12-01 20:46:20

问题


I have this Dijit number spinner:

<div class="extra_field hide_on_load form_action_fy">
    <label>Action Fiscal Year</label>
    <input name="form_action_fy" id="form_action_fy"
        data-dojo-type="dijit.form.NumberSpinner" 
        data-dojo-props="
            value:@ViewBag.fy,
            smallDelta:1, 
            largeDelta:1, 
            constraints:{min:2010,max:2020,places:0}"
    />
</div>

After this input loses focus, a comma is added. How do I prevent this comma from showing? That is, I don't want 2,011 but rather 2011.

Thanks! Eric


回答1:


The simple answer is to add pattern:'#' to your constraints object.

The pattern property allows you to specify how you want your numeric data to be displayed. Here is a link to dojo's reference on number patterns. The whole page is pretty informative on formatting numbers.

Your example should end up looking something like this:

<div class="extra_field hide_on_load form_action_fy">
    <label>Action Fiscal Year</label>
    <input name="form_action_fy" id="form_action_fy"
        data-dojo-type="dijit.form.NumberSpinner" 
        data-dojo-props="
            value:2011,
            smallDelta:1, 
            largeDelta:1, 
            constraints:{min:2010,max:2020,places:0,pattern:'#'}"
    />
</div>


来源:https://stackoverflow.com/questions/7996427/dojo-how-to-remove-comma-from-value

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!