Correct maskMoney formatting
Correct maskMoney formatting
klermann
Posts: 277Questions: 67Answers: 1
Could you help me display the correct maskMoney formatting in this field, I can display the field, but I could not display the mask correctly, just display the numbers?
(function( factory ){
if ( typeof define === 'function' && define.amd ) {
// AMD
define( ['jquery', 'datatables', 'datatables-editor'], factory );
}
else if ( typeof exports === 'object' ) {
// Node / CommonJS
module.exports = function ($, dt) {
if ( ! $ ) { $ = require('jquery'); }
factory( $, dt || $.fn.dataTable || require('datatables') );
};
}
else if ( jQuery ) {
// Browser standard
factory( jQuery, jQuery.fn.dataTable );
}
}(function( $, DataTable ) {'use strict';
if ( ! DataTable.ext.editorFields ) {
DataTable.ext.editorFields = {};
}
var _fieldTypes = DataTable.Editor ?
DataTable.Editor.fieldTypes :
DataTable.ext.editorFields;
_fieldTypes.money = {
create: function ( conf ) {
var that = this;
conf._input = $(
'<div class="input-group date" id="'+conf.id+'">'+
'<input id="valorReceita" type="text" class="form-control" />'+
'<span class="input-group-addon"><span class="wb-money"></span>'+
'</span>'+
'</div>'
)
.attr( $.extend( {}, conf.attr ) )
.maskMoney( $.extend( {}, conf.opts ) );
return conf._input[0];
},
get: function ( conf ) {
return conf._input.children('input').val();
},
set: function ( conf, val ) {
/* var picker = conf._input.data("maskMoney");
console.log(picker);
if ( picker.setDate ) {
picker.setDate( val );
}
else {
picker.date( val );
} */
},
disable: function ( conf ) {
conf._input.data("maskMoney").disable();
},
enable: function ( conf ) {
conf._input.data("maskMoney").enable();
},
inst: function ( conf ) {
return conf._input.data("maskMoney");
}
};
}));
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
I have no idea what is or isn't wrong with your code. I am using this which I copied from somewhere and it works with the data tables masking plugin (Field Type - Mask and jQuery Mask available here https://datatables.net/download/index).
I use this to assign the respective classe to the Editor field:
Then I use this to trigger the function:
This thread appears to be a duplicate / continuation of your other thread on this topic. Could you not post duplicates please?
The problem appears to be that you are applying the
maskMoney
jQuery plug-in to adiv
element, not theinput
. You need to apply it to theinput
element. Something like$('input', conf._input).maskMoney();
- I guess. Although I haven't read though their documentation.Allan
Well, I was looking for the same script to use and also have not resolved its implementation in DataTables yet, but I can give you my part of the create, set and get routines.
I am using field type "moneymask".
The code below is only the part of create, set and get.
I still not resolved 2 issues; first of all: entering the field will only give "Uncaught TypeError: Cannot read property 'createRange' of undefined" - errors, and secondly the mask is not applied giving problems when returning the value. With autocomplete I can select 5.5 and it returns 5.5 but with the keyboard, I can not enter a point and I will receive a value 100 times less and only with 2 numbers. Maybe it might help you a little bit further.
@klermann
I forgot to mention your name in my previous post. Now you will be notified I guess??
Hello @Tester2017, I solved this money mask problem and the way I needed it, take a look at the example, if you need the plugin posted to you!
@klermann,
OK, looks very good. And thanks for your offer, but I finally decided to let moneymask away and only use the built-in render function for presentation of money values and jquery-mask for the data-entry part, which is working perfectly for me. Bom final de semana!