Git Product home page Git Product logo

Comments (2)

esoyke avatar esoyke commented on August 24, 2024

I found a workaround that seems to work. In the safeVal() method in credit-card.ts, I advance the cursor by one if it's at the end of a 4 digit segment:

try {
	cursor = target.selectionStart;
	if(cursor==4 || cursor==9 || cursor==14 || cursor==19){
		cursor++;
	}
} catch (error) {}

from angular-cc-library.

esoyke avatar esoyke commented on August 24, 2024

I refined it a little further to automatically delete the value to the right of the space, and also only do so if they hit the Delete key. In the reFormatCardNumber() method of credit-card-directive, I check if it's a Delete event:

if(e instanceof KeyboardEvent && e.code.toUpperCase()=='DELETE')
	deleteKey = true;

Pass that deleteKey flag as a new boolean input to safeVal(), then only if a delete was performed, advance the cursor and delete the digit past the space.

try {
	cursor = target.selectionStart;
	if(deleteKey && (cursor==4 || cursor==9 || cursor==14 || cursor==19)){
		cursor++;
		// simulate another delete event by removing the character the user would have indented to delete
		let  preDeleteSegment = value.substring(0, cursor);
		let  postDeleteSegment = value.substring(cursor+1, value.length);
		value = preDeleteSegment+postDeleteSegment;
	}
} catch (error) {}

from angular-cc-library.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.