Currency type formatting error in jquery

Asked

Viewed 136 times

-1

I’m creating a mask in my field like this:

$("#ValorMultaSt").mask('000.000.000,00', { reverse: true });

When I type some value works perfectly, but when I perform any action on the screen it puts a "." in front, as in the example:

If I type 444,44 after performing an action on the screen the value is changed to .444,44

Javascript function:

function AtualizarMascaras() {
            // Mascaras
            $("#ValorPorcentagemField").mask('000', { reverse: true });
            $("#ValorMultaSt").mask('000.000.000,00', { reverse: true });
            $("#ValorMultaAcrescimoSt").mask('000.000.000,00', { reverse: true });
            $("#ValorMultaFaixaMinimaSt").mask('000.000.000,00', { reverse: true });
            $("#ValorMultaFaixaMaximaSt").mask('000.000.000,00', { reverse: true });
            $("#DataPublicacao").mask('00/00/0000');
        }

Function calling mask update function:

$(function () {           

            $(document).ajaxComplete(function () {
                AtualizarMascaras();
            });

            AtualizarMascaras();
});

Div html from the field:

<div class="row" id="divValorMulta">
                    <div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
                        <div class="form-group">
                            <div class="row">
                                <div class="col-xs-4 col-sm-4 col-md-4 col-lg-4">
                                    @Html.LabelFor(model => model.ValorMultaSt, "Valor da Multa")
                                </div>
                                <div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
                                    @Html.EditorFor(model => model.ValorMultaSt, new { htmlAttributes = new { @class = "form-control", disabled, @placeholder = "R$" } })
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

Someone can help me?

  • Use the Jquery-maskMoney plugin. See Here

  • 1

    What "action" would that be?

  • no, already removed and continues the same error

  • At what point is this code executed? Post this excerpt as well, in your question. What type of action causes the value to be changed incorrectly?

  • Any action you take Ubmit to the screen....

  • "Reverse: true" is to put the mask from right to left.

  • Try to simulate here or in jsfiddle.

  • @Netinho Santos, already removed, the error remains...

  • It is not "Reverse: true" that is causing the error. As I said, it is to put the mask from right to left. Try to simulate here by putting the full code.

  • posted the complete code...

  • Put the already rendered HTML in the browser. CTRL + U

  • <input class="form-control text-box single-line" id="Valormultast" name="Valormultast" placeholder="R$" type="text" value=" 333,33" maxlength="14" autocomplete="off">

Show 7 more comments

1 answer

3


You can use another plugin specifically for coin masks. Maskmoney

Your code would look like this.

function AtualizarMascaras() {
            // Mascaras
        $("#ValorPorcentagemField").maskMoney({prefix:'R$ ', allowNegative: true, thousands:'.', decimal:',', affixesStay: false});
        $("#ValorMultaSt").maskMoney({prefix:'R$ ', allowNegative: true, thousands:'.', decimal:',', affixesStay: false});
        $("#ValorMultaAcrescimoSt").maskMoney({prefix:'R$ ', allowNegative: true, thousands:'.', decimal:',', affixesStay: false});
        $("#ValorMultaFaixaMinimaSt").maskMoney({prefix:'R$ ', allowNegative: true, thousands:'.', decimal:',', affixesStay: false});
        $("#ValorMultaFaixaMaximaSt").maskMoney({prefix:'R$ ', allowNegative: true, thousands:'.', decimal:',', affixesStay: false});
        $("#DataPublicacao").maskMoney({prefix:'R$ ', allowNegative: true, thousands:'.', decimal:',', affixesStay: false});
        }
  • 1

    thanks, it worked out.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.