I am trying to validate local decimal numbers (Portuguese -> pt-PT) but I get a console error in the Browser:
Uncaught TypeError: t.parseFloat is not a function. Exception occurred when checking element SizeOpenedWidth, check the 'number' method.
In Portugal, the decimal separator is the ",", so a valid decimal number here is "10,21".
The script I use to load Globalization:
$.when(
$.getJSON("/Scripts/cldr/supplemental/likelySubtags.json"),
$.getJSON("/Scripts/cldr/main/numbers.json"),
$.getJSON("/Scripts/cldr/main/ca-gregorian.json"),
$.getJSON("/Scripts/cldr/supplemental/timeData.json")
).then(function () {
// Normalize $.get results, we only need the JSON, not the request statuses.
return [].slice.apply( arguments, [ 0 ] ).map(function( result ) {
return result[ 0 ];
});
}).then( Globalize.load ).then(function() {
Globalize.locale("pt-PT");
});
On the View I use unobtrusive validation:
<div class="form-group">
@Html.LabelFor(model => model.SizeOpenedWidth, htmlAttributes: new { @class = "control-label col-md-3" })
<div class="col-md-3">
<div class="input-group">
@Html.EditorFor(model => model.SizeOpenedWidth, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.SizeOpenedWidth, "", new { @class = "text-danger" })
</div>
</div>
</div>
To load all the libraries, I use the Shared/Layout file:
<script src="/Scripts/jquery/jquery-2.1.4.js"></script>
<script src="/Scripts/cldr.js"></script>
<script src="/Scripts/cldr/event.js"></script>
<script src="/Scripts/cldr/supplemental.js"></script>
<script src="/Scripts/cldr/unresolved.js"></script>
<script src="/Scripts/globalize.js"></script>
<script src="/Scripts/globalize/number.js"></script>
<script src="/Scripts/globalize/date.js"></script>
<script src="/Scripts/moment.min.js"></script>
<script src="/Scripts/moment-with-locales.min.js"></script>
<script src="/Scripts/bootstrap/bootstrap.js"></script>
<script src="/Scripts/respond/respond.js"></script>
<script src="/Scripts/jquery/jquery.validate.min.js"></script>
<script src="/Scripts/jquery/jquery.validate.globalize.min.js"></script>
<script src="/Scripts/jquery/jquery.validate.unobtrusive.min.js"></script>
<script src="/Scripts/bootstrap-datetimepicker.js"></script>