开发者

Bypassing value set with InputNumber widget

I have an MVC view that is using cached values to display to the user via

@Html.TextboxFor(x => x.SomeInteger, new { @class="selector" });

and similar constructs.

My problem is that when I do this

$(“.selector”).wijinputnumber({
    type: ‘numeric’,
    minValue: 0,
    decimalPlaces: 0,
    showSpinner: true
});

The value of the textbox gets set to 0, but (for example) the user could have put in 4 previously and I need it to reflect that. Also, I've verified that my Model does actually have 4 in the SomeInteger property, so it's not that.

Is there a way to tell wijinputnumber to not set an initial value?

Here's a full example of just HTML and Wijmo/jQuery that exhibits this problem:

<!DOCTYPE HTML>
<html>
<head>
    <link href="http://cdn.wijmo.com/themes/rocket/jquery-wijmo.css" rel="stylesheet" type="text/css" />
    <link href="http://cdn.wijmo.com/jquery.wijmo-open.1.1.2.css" rel="stylesheet" type="text/css" />
    <link href="http://cdn.wijmo.com/jquery.wijmo-complete.1.1.2.css" rel="stylesheet" type="text/css" />
    <script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.4.min.js" type="text/javascript"></script>
    <script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/jquery-ui.min.js" type="text/javascript"></script>
    <script src="http://cdn.wijmo.com/external/jquery.bgiframe-2.1.3-pre.js" type="text/javascript"></script>
    <script src="http://cdn.wijmo.com/external/jquery.glob.min.js" type="text/javascript"></script>
    <script src="http://cdn.wijmo.com/external/jquery.mousewheel.min.js" type="text/javascript"></script>
    <script src="http://cdn.wijmo.com/external/raphael-min.js" type="text/javascript"></script>
    <script src="http://cdn.wijmo.com/jquery.wijmo-open.1.1.2.min.js" type="text/javascript"></script>
   开发者_开发问答 <script src="http://cdn.wijmo.com/jquery.wijmo-complete.1.1.2.min.js" type="text/javascript"></script>
</head>
<body>  
    <input type="text" class="correct" value="5" />

    <input type="text" class="notcorrect" value="10" /> 

    <script type="text/javascript">
        jQuery(document).ready(function($) {
            $('.correct').wijtextbox();         

            $(".notcorrect").wijinputnumber({
            type: 'currency',
            decimalPlaces: 2,
            showGroup: true,
            showSpinner: true
            });             
        });
    </script>
</body>
</html>


You could use the val() function on an element to get its value

<script type="text/javascript">
    jQuery(document).ready(function($) {
        $('.correct').wijtextbox();         

        $(".notcorrect").wijinputnumber({
            type: 'currency',
            decimalPlaces: 2,
            showGroup: true,
            showSpinner: true,
            value: $(".notcorrect").val()
        });             
    });
</script>

Hope this helps,

Matt


It turns out this is a bug in Wijmo currently, but a work around from this post is as follows:

$(“.selector”).each(function () {
var n = $(this).val();
$(this).wijinputnumber(
{
type: ‘numeric’,
minValue: 0,
decimalPlaces: 0,
showSpinner: true,
value: n
});
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜