question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

how to apply cleave.js format for multiple input with one class

See original GitHub issue

So, a question in a title. I have a problem, I have some inputs in form with class ‘date’ code works fine, but it works for first input (for the first got the top down with that class)

var cleave = new Cleave('.date', {
		    date: true,
		    datePattern: ['d', 'm', 'Y'],
		    delimiter: '.'
		});

how can I use this code for multiple inputs without dublicating code applying it by selector ‘#elemname’ need to apply it to all by class ‘.date’

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:7
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

64reactions
lesleyblankendalcommented, Dec 19, 2016

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

13reactions
BilalBudhanicommented, Jul 25, 2018

If you want to use it without jQuery, Here is how it can be done

document.querySelectorAll('input').forEach(function(el) {
  new Cleave(el, {...options});
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Why can't I establish two cleave.js formatted fields in the same ...
I've tried a few remixes of this including assigning the Cleave objects to variables and declaring them in the same function, but no...
Read more >
Format Input Fields Automatically with Cleave.js - Hongkiat
Think about all the different input fields that require a formatted structure. Phone numbers, credit cards, birth dates, street addresses...
Read more >
Input Formatting with Cleave.js - Medium
Cleave is a JavaScript library that handles the formatting of input values, in a clean and easy to implement pattern, so that you...
Read more >
Auto-formatting input text content with cleave.js - YouTube
In this video you will learn how to automatically format you input content when you are typing. Download Cleave. js : ...
Read more >
cleave.js - Format Examples - CodePen
2. <section>. 3. <p>Credit card detector (<span class="type">unknown</span>): </p> ... <input class="input-1 right" /> ... <p>Use multiple delimiters:</p>.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found