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.

Change mask pattern on the fly

See original GitHub issue

Is it possible to change mask pattern on the fly? I would like something like that . If you start with 04 it changes it mask pattern.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
RicardoZamboncommented, Aug 6, 2019

Sorry update this closed topic, but adding more information in case anybody need this in the future, I was in need of a custom format accordingly to the field length.

The @uebbi example helped, but wasn’t complete, before setting the new Cleave() was needed destroy the previous instance.

Here is the complete code:

var activeFormat;

$('.cpfj').on('keyup', function() {
    if (activeFormat != null) {
        activeFormat.destroy();
        activeFormat = null;
    }
    
    if ($(this).val().length <= 14) {
        activeFormat = new Cleave('.cpfj', {
            numericOnly: true,
            blocks: [3, 3, 3, 3],
            delimiters : ['.', '.', '-']			
        });
    }
    else {
        activeFormat = new Cleave('.cpfj', {
            numericOnly: true,
            blocks: [2, 3, 3, 4, 2],
            delimiters : ['.', '.', '/', '-']
        });			
    }
});

And here is the Fiddle example, hope this help.

https://jsfiddle.net/Ricardozambon/kyx4c96n/

0reactions
RicardoZamboncommented, Aug 6, 2019

To fix the issue with the backspace, you must not reapply the mask format when the previous field length is equal to the current length.

I’ve updated the fiddle with this fix.

var oldValue = '';
if ($(this).data('old_val') != undefined) { oldValue = $(this).data('old_val'); }

var currentValue = this.value;
if (activeFormat != null) { currentValue = activeFormat.getRawValue(); }

if (oldValue.length != currentValue.length) {
    $(this).data('old_val', currentValue);
    ...
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Resize or Change Face Mask Pattern - YouTube
#facemask #facemaskpattern # alterfacemask In this video, I will show you how to resize a paper mask pattern to suit you personal needs...
Read more >
Resize Your Face Mask Pattern for a Perfect Fit ... - YouTube
In this video, I will show you how to resize a Mask Pattern for a custom fit and coverage. This video is intended...
Read more >
INFINITY'S GUIDE TO - FLY MASK MAKING!!! - YouTube
These ADORABLE tack pieces are SUPER EASY to make and I hope this tutorial was helpful in aiding you bring your fly masks...
Read more >
How to Sew a 3D Face Mask: With ONE Pattern Piece!
Your browser can't play this video. Learn more. Switch camera.
Read more >
Tutorial: How to Sew a Face Mask for Hospitals - YouTube
Help us sew 1 Million masks for the hospitals in a time of need. Join our challenge and come ... To Download Pattern...
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