jQuery.inputmask and its placeholder

330 views Asked by At

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

There are 2 answers

1
Viacheslav Ravdin On 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.

0
76484 On

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>