I use jQuery to currency my data for this page Masked-Money, and I want to use 'unmasked' because in my model I have decimal, and mas are not allowed in decimal values.
When I use without 'unmasked' it works well:
<script>
$(function () {
$('#Total').maskMoney();
})
</script>
but If I use unmasked, plugin doesn't works
<script>
$(function () {
$('#Total').maskMoney('unmasked');
})
</script>
What I'm doing wrong, or what can I do to delete ma when I post
I use jQuery to currency my data for this page Masked-Money, and I want to use 'unmasked' because in my model I have decimal, and mas are not allowed in decimal values.
When I use without 'unmasked' it works well:
<script>
$(function () {
$('#Total').maskMoney();
})
</script>
but If I use unmasked, plugin doesn't works
<script>
$(function () {
$('#Total').maskMoney('unmasked');
})
</script>
What I'm doing wrong, or what can I do to delete ma when I post
Share Improve this question asked Nov 6, 2015 at 0:34 GerryGerry 611 silver badge4 bronze badges 1-
No familiar with that plugin, but you either need to create a custom model binder so that the value can be bound to your property, or you need to intercept the forms
.submit()
event and update the value of the hidden input so its submitted with the 'unmasked' value - e.g.$('form').submit(function() { var t = $('#Total').maskMoney('unmasked'); $('#Total').val(t); });
– user3559349 Commented Nov 6, 2015 at 1:20
3 Answers
Reset to default 3Looking at the demo page, you have two options:
Provide some setup to the plugin
$('#Total').maskMoney({thousands:''});
Set some data properties on your input
@Html.TextboxFor(m => m.Total, new { data_thousands=""})
Update.
Apologies, got the wrong end of the stick.
You would need to tie onto the submit event as stephen says and change the value to the correct version. something like this.
$(function(){
$("form").submit(function() {
$('#Total').val($('#Total').maskMoney('unmasked')[0]);
});
});
That really worked for me:
$("#form-id").submit(function(){
var value = $('#input-value-id').maskMoney('unmasked')[0];
$('#input-value-id').val(value);
});
i have many input in a single form That's why i used the following codes
$('.field').maskMoney('destroy');
$('.field').maskMoney({thousands:'', decimal:'.'});
$('.field').maskMoney('mask');