Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to apply AutoNumeric to all selectors?

Tags:

javascript

class: float

With this example, AutoNumeric applied only to the first element input with class the float.

    <script src = "https://unpkg.com/autonumeric" ></script>
    
    <form>   
      <input type="text" class="form-control cell-in-text float" id="26" asp-for="@Model.ListEtpAnswer.ElementAt(26).Answer" />
    <br />
      <input type="text" class="form-control cell-in-text float" id="27" asp-for="@Model.ListEtpAnswer.ElementAt(27).Answer" /> 
     <br /> 
      <input type="text" class="form-control cell-in-text float" id="28" asp-for="@Model.ListEtpAnswer.ElementAt(28).Answer" /> 
     <br /> 
     
    
    <script>
      const autoNumericOptions = {
        allowDecimalPadding: "floats",
        decimalCharacter: ",",
        digitGroupSeparator: "",
        //emptyInputBehavior: "zero",
        watchExternalChanges: true
      };
    new AutoNumeric(".float", autoNumericOptions); 
    </script>
like image 503
Дмитрий Avatar asked Oct 27 '25 07:10

Дмитрий


1 Answers

You need to use Autonumeric.multiple to apply it to multiple elements at once.

<script src = "https://unpkg.com/autonumeric" ></script>
    
    <form>   
      <input type="text" class="form-control cell-in-text float" id="26" asp-for="@Model.ListEtpAnswer.ElementAt(26).Answer" />
    <br />
      <input type="text" class="form-control cell-in-text float" id="27" asp-for="@Model.ListEtpAnswer.ElementAt(27).Answer" /> 
     <br /> 
      <input type="text" class="form-control cell-in-text float" id="28" asp-for="@Model.ListEtpAnswer.ElementAt(28).Answer" /> 
     <br /> 
     
    
    <script>
      const autoNumericOptions = {
        allowDecimalPadding: "floats",
        decimalCharacter: ",",
        digitGroupSeparator: "",
        //emptyInputBehavior: "zero",
        watchExternalChanges: true
      };
    AutoNumeric.multiple(".float",null, autoNumericOptions); 
    </script>
like image 53
Igor Litvinovich Avatar answered Oct 28 '25 21:10

Igor Litvinovich



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!