Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not work for input type numbers #16

Open
vimkaf opened this issue Jun 4, 2024 · 2 comments
Open

Does not work for input type numbers #16

vimkaf opened this issue Jun 4, 2024 · 2 comments

Comments

@vimkaf
Copy link

vimkaf commented Jun 4, 2024

whenever i format <input type="number" /> I get the error

The specified value "1,212" cannot be parsed, or is out of range
This is my JS code

const cleaveZen = window.cleaveZen;
const { formatNumeral } = cleaveZen;

const currencyInputs = document.querySelectorAll(".currencymask");

currencyInputs.forEach((currencyInput) => {
  currencyInput.addEventListener("input", (e) => {
    currencyInput.value = formatNumeral(e.target.value, {
      numeralThousandsGroupStyle: "thousand",
    });
  });
});
@pakacoder
Copy link

pakacoder commented Sep 11, 2024

It works if you use type="text"

    <label>
        <input class="currency-input" 
               type="text"
               value = "12345.8"
        />
    </label>

@rodrigopedra
Copy link

Besides using type="text" as @pakacoder noted, to keep the numeric input on mobile keyboards, add inputmode="numeric"

reference: https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/inputmode#numeric

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants