Form zero values greater than 999.99

2

I'm going through a problem I've never seen before. I'm hoping someone has seen and can help me.

I'm working with asp.net mvc 5, and sending a form via post to my controller.

My model:

<div class="col-md-6">
    <form action="@Url.Action("Create","DadosManuais")" method="get" class="form-horizontal">
meus campos aqui...
</div>

My controller:

public ActionResult Create(DadosManuaisCreate dados){
     Algumas linhas de código...
}

I'm also using jquery to create the masks in the model:

@section Scripts{
@Scripts.Render("~/bundles/jqueryval")
<script type="text/javascript">
        $(document).ready(function () {
$("#periodo").inputmask("mm/yyyy");
            $("#tacGestor").maskMoney({ showSymbol: true, symbol: "R$", 
                decimal: ",", thousands: "." });
            $("#vlEsperado").maskMoney({ showSymbol: true, symbol: "R$", 
                decimal: ",", thousands: "." });
            $("#vlAdquirido").maskMoney({ showSymbol: true, symbol: "R$", 
                decimal: ",", thousands: "." });
            $("#selic").maskMoney({ showSymbol: true, symbol: "R$", decimal: 
                ",", thousands: "." });
            $("#premioSelic").maskMoney({ showSymbol: true, symbol: "R$", 
                decimal: ",", thousands: "." });
            $("#seguro").maskMoney({ showSymbol: true, symbol: "R$", 
                decimal: ",", thousands: "." });
            $("#despesas").maskMoney({ showSymbol: true, symbol: "R$", 
                decimal: ",", thousands: "." });
            $("#naoIdentificados").maskMoney({ showSymbol: true, symbol: 
                "R$", decimal: ",", thousands: "." });
            $("#qtdContratosAtivos").inputmask("9{1,3}.9{1,3}.9{1,3}");
        });
</script>   
}

Note that at the end of the command in jquery, there is a parameter " thousands:". "} "

This says that for thousands, the dot (".") will be used to divide.

My problem happens when I press the submit button. the object is instantiated per parameter in the controller, but fields containing numbers larger than 999.99 are zeroed.

Look:

Iremovedtheparameter" thousands:". "} " and the problem stopped occurring:

How to work around this problem without removing my mask?

Very grateful!

PS: No data posted here is real. They are all used to simulate an insert in the system.

    
asked by anonymous 17.07.2017 / 21:38

1 answer

1

You just need to format the before data to send to the controller, since the json parser does not interpret the points used to divide the multiples of 1000.

p>

Then:

$( '#idDoForm' ).submit( () => {
   ///Quando o form for enviado
   let $inputs = $( '.formatar' );
   ///Coloque essa classe em todos os campos que vão zerados caso passem de 1000
   $inputs.each( (indice, input) => { 
       ///Para cada input com a classe 'formatar'
       let $input = $(input);

       ///Trocamos todos os pontos por nada
       $input.val( $input.val().replace(/\./g,''));
   })

   ///Submit
   return true;
})

Edit:

var submit = false;
$( '#idDoForm' ).submit( () => {
   ///Toda a logica de antes aqui...

   if(!submit)
       setTimeout( () => {
           submit = true;
           $( '#idDoForm' ).submit();
       },300);//Vamos dar um tempo para o jQuery mudar o form
   ///Submit
   return submit;

})
    
20.07.2017 / 17:03