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

Cannot get multiple cleave instances working on a selector #462

Open
iofacture opened this issue Apr 19, 2019 · 1 comment
Open

Cannot get multiple cleave instances working on a selector #462

iofacture opened this issue Apr 19, 2019 · 1 comment

Comments

@iofacture
Copy link

iofacture commented Apr 19, 2019

Disclaimer - I am not a Javascipt genius but this has thrown me for a loop - perhaps I'm doing something obviously wrong

I ended up using

$('.zip-code').toArray().forEach(function(field){
new Cleave(field, {
  numericOnly: true,
  delimiter: ' ',
  blocks: [5,4]
});

from http://stackoverflow.com/questions/40637035/why-cant-i-establish-two-cleave-js-formatted-fields-in-the-same-js-file

I am using the latest version of cleave and this is my stack trace:

Uncaught TypeError: Cannot read property 'length' of undefined
at Object.getNextCursorPosition (cleave.min.js:8)
at i.updateValueState (cleave.min.js:8)
at i.onInput (cleave.min.js:8)
at init (cleave.min.js:8)
at new i (cleave.min.js:8)
at 2001:368
at Array.forEach ()
at 2001:367

For the following:

on a simple table with < td class="dollar-amount" >

<script type="text/javascript">

    $('.dollar-amount').toArray().forEach(function (field) {
        new Cleave(field, {
            numeral: true,
            prefix: '$'
        });
    });

</script>

I have confirmed with debugger that the selector is returning an array of elements

image

Originally posted by @iofacture in #138 (comment)

@nosir
Copy link
Owner

nosir commented Jun 29, 2019

On td elements? The lib expects to obtain input fields as the element, if this helps

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

2 participants