GithubHelp home page GithubHelp logo

Currency Mask about v-mask HOT 14 CLOSED

probil avatar probil commented on June 19, 2024
Currency Mask

from v-mask.

Comments (14)

kylemilloy avatar kylemilloy commented on June 19, 2024 1

from v-mask.

dougiefresh49 avatar dougiefresh49 commented on June 19, 2024 1

a workaround for using the createNumberMask function until the PR is merged is as follows

// in your vue component, in the computed properties

mask() {
      const currencyMask = createNumberMask({
          prefix: '$',
          allowDecimal: true,
          includeThousandsSeparator: true,
          allowNegative: false 
      });
      currencyMask(this.value)
          .map(v => String(v) === '\/\\d/' ? '#' : v)
          .filter(v => v !== '[]')
          .join('');
    }

it takes the output of the currency mask and transforms it to the expected string input of v-mask

from v-mask.

alicesouto avatar alicesouto commented on June 19, 2024

May anyone help me, please? :)

from v-mask.

nickforddev avatar nickforddev commented on June 19, 2024

One way to achieve this that doesn't seem too crazy to me is to allow for a special character that can be mapped to a regex, and then map the regex to allow for digits, as well as commas and periods. Then you can use a function similar to the filter to process this amount on blur.

The markup might look something like <input type="text" v-mask="'RRRRRR'" v-mask-pattern="/[0-9.]/" v-model="myInputModel">.

I implemented a similar feature using the jquery mask plugin years ago.

@probil Would it be difficult to add an option for custom regex patterns? I'd be happy to take a look if you are open to a PR...

from v-mask.

nickforddev avatar nickforddev commented on June 19, 2024

@alicesouto I couldn't wait for a response on this, so I created a component that masks the input, here's a gist: https://gist.github.com/nickforddesign/014639c694eaf2c88c3e1f323ba5b755

I had a few strong opinions about this that others might disagree with, like forcing the cursor to the end of the input on focus using the event.value = event.value trick, I also always stick to 2 decimal places, so if the user inputs 12.5, it is converted to 12.50...

from v-mask.

probil avatar probil commented on June 19, 2024

Not yet supported by I have planed to make it work

from v-mask.

euricovidal avatar euricovidal commented on June 19, 2024

+1

from v-mask.

thearabbit avatar thearabbit commented on June 19, 2024

+1

from v-mask.

kylemilloy avatar kylemilloy commented on June 19, 2024

+11111111

from v-mask.

probil avatar probil commented on June 19, 2024

I'm busy right now to implement but it's not hard to implement.
Since we use text-mask-core under the hood we can use addons to archive that.

There is createNumberMask addon which can be used to format user input as currency
https://github.com/text-mask/text-mask/tree/master/addons/#createnumbermask

PR is welcome.

from v-mask.

kylemilloy avatar kylemilloy commented on June 19, 2024

ah I forgot I was going to write something for this..lemme give it a go.

from v-mask.

dougiefresh49 avatar dougiefresh49 commented on June 19, 2024

@kylemilloy check out pr #455, see if its what you were thinking

from v-mask.

kylemilloy avatar kylemilloy commented on June 19, 2024

Close to what I was thinking.

I was working on something to just accept an object where you pass it a mask type with options so you can do this all inline without any configuration or importing of additional libraries. Just do a quick <input v-mask="{type: 'number', options: {prefix: '$', }}" /> kind of idea.

Your way is definitely more flexible however.

from v-mask.

github-actions avatar github-actions commented on June 19, 2024

🎉 This issue has been resolved in version 2.2.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

from v-mask.

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.