skip to Main Content

Here is my code:

                        $("input").inputmask("decimal", {
                            "radixPoint": ",",
                            "groupSeparator": " ",
                            "digits": 2,
                            "autoGroup": true,
                            "digitsOptional": true,
                            "suffix": " EUR",
                            "placeholder": "129,5",
                            "clearMaskOnLostFocus": false,
                        })

Everything works great but I don’t really understand how to display "129,5" as a placeholder instead of "1"?

Thanks in advance for your help!

I tried to search within StackOverflow and read the official documentation for jQuery.inputmask, but it didn’t help.

2

Answers


  1. Chosen as BEST ANSWER

    I looked through jQuery.inputmask source codes and understood that there's nothing to do about it so I had to find out different approach.


  2. The docs for the inputmask plugin contain a section on Setting Initial Values.

    It states that you just need to set the value attribute of the input.

    You could do this in HTML, ex: <input value="129,5">

    Alternatively, you could do it with jQuery:

    $(function () {
      $("input")
        .val("129,5")
        .inputmask("decimal", {
          "radixPoint": ",",
          "groupSeparator": " ",
          "digits": 2,
          "autoGroup": true,
          "digitsOptional": true,
          "suffix": " EUR",
          "clearMaskOnLostFocus": false,
        });
    });
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.inputmask.min.js"></script>
    <input>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search