maskMoney without needing to select the input

2

I'm using maskMoney but it only formats value if I click on input, how can I change it? Or is it formatted as soon as the page loads?

$(function() {

  $("input").maskMoney({
    allowNegative: true,
    thousands: '.',
    decimal: ',',
    affixesStay: false
  });

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/jquery-maskmoney/3.0.2/jquery.maskMoney.min.js"></script>
<input type="text" value="-90.00"/>
    
asked by anonymous 11.07.2016 / 18:52

1 answer

2

You can force formatting by firing the mask.maskMoney event.

$(function() {
  var maxLength = '-0.000.000,00'.length;
  
  $("input").maskMoney({
    allowNegative: true,
    thousands: '.',
    decimal: ',',
    affixesStay: false
  }).attr('maxlength', maxLength).trigger('mask.maskMoney');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/jquery-maskmoney/3.0.2/jquery.maskMoney.min.js"></script>
<input type="text" value="-90.00"/>
    
11.07.2016 / 19:36