Giter VIP home page Giter VIP logo

Comments (7)

waterplea avatar waterplea commented on June 3, 2024 2

We probably also need a way to format an arbitrary string with given MaskitoOptions 🤔

from maskito.

Foprta avatar Foprta commented on June 3, 2024

Since there is no function to get a resulted formatting like formatValue(value: string): string i've decided to use a hack to fire input event and trigger all the maskito processing:

    const originalWriteValue = this.ngControl.valueAccessor.writeValue.bind(this.ngControl.valueAccessor);

    this.ngControl.valueAccessor.writeValue = (obj: any) => {
      originalWriteValue(obj);

      this.elRef.nativeElement.dispatchEvent(new Event("input"));
    };

Edit: But this leads to multiple valueChanges events.

from maskito.

Foprta avatar Foprta commented on June 3, 2024

Would be great to have this method in the Maskito class itself.

from maskito.

nsbarsukov avatar nsbarsukov commented on June 3, 2024

Input is not formatted after setting value via FormControl methods setValue, patchValue, reset.

Maskito libraries were created to prevent user from typing invalid value.
Maskito listens beforeinput and input events.
Programatic changes of input's value (by developer) don't trigger these events!
Of course, we can use MutationObserver to detect these programatic changes. But it is overkill.

Maskito is based on the assumption that developer is capable to programatically patch input with valid value.

However, Alex suggests good idea that we can add utility-helper for these cases:

We probably also need a way to format an arbitrary string with given MaskitoOptions 🤔

This issue will be solved in the following issue

from maskito.

Foprta avatar Foprta commented on June 3, 2024

Well, it is not affects me as i'm not using the @maskito/angular library, but as an Angular developer i assume that angular-library would properly support Angular features by default. Otherwise it seems like a useless library, because you still need to implement your own Angular logic.

from maskito.

waterplea avatar waterplea commented on June 3, 2024

Well, it is not affects me as i'm not using the @maskito/angular library, but as an Angular developer i assume that angular-library would properly support Angular features by default. Otherwise it seems like a useless library, because you still need to implement your own Angular logic.

@nsbarsukov I think other masking solutions watch for programmatic changes too.

from maskito.

nsbarsukov avatar nsbarsukov commented on June 3, 2024

@nsbarsukov I think other masking solutions watch for programmatic changes too.

We can take our legacy text-mask as an example.

Programatic update of the value via vanilla JS doesn't trigger value's validations.
Screenshot 2023-03-06 at 14 52 42

Angular package angular2-text-mask implements ControlValueAccessor.
Our library doesn't do it (because it doesn't always have direct access to native input).
We suppose that library can be used with Taiga UI, Material, Ant and other design libraries.

from maskito.

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.