0.3.6 • Published 5 months ago

simple-input-formatter v0.3.6

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

Simple Input Formatter

See an example https://jon49.github.io/simple-input-formatter/.

Format the input element to whatever you like and only submit the raw data.

This custom element is 1.1 kB minified.

Define your formatter:

(() => {
    let USDollar = new Intl.NumberFormat('en-US', {
        style: 'currency',
        currency: 'USD',
    }); 

    window.currency = {
        format(value) {
            return USDollar.format(value)
        },
        isValid(value) {
            return (isNaN(value))
                ? 'Must be a number'
            : ''
        }
    }
})()

Put on your HTML page:

<form>
    <format-input data-format="currency">
        <input
            type="number"
            step="2"
            name="test"
            placeholder="Give me a number!">
    </format-input>
    <button>OK</button>
</form>

See the tests to see how it works!

Change Log

0.3.0

Improved handling of invalid data.

Added ability to insert error message in element using data-show-invalid.

0.3.0

5 months ago

0.2.1

6 months ago

0.2.0

6 months ago

0.3.6

5 months ago

0.3.5

5 months ago

0.3.2

5 months ago

0.3.1

5 months ago

0.2.2

6 months ago

0.3.4

5 months ago

0.3.3

5 months ago

0.1.5

8 months ago

0.1.4

8 months ago

0.1.3

8 months ago

0.1.2

8 months ago

0.1.1

8 months ago

0.1.0

8 months ago