Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could I use in Element UI? #6

Open
thearabbit opened this issue Feb 2, 2018 · 10 comments
Open

Could I use in Element UI? #6

thearabbit opened this issue Feb 2, 2018 · 10 comments

Comments

@thearabbit
Copy link

<el-input v-mask="'99/99/9999'" v-model="inputMask"></el-input>

But don't work

@bapa92
Copy link

bapa92 commented Mar 13, 2018

https://github.com/vuejs-tips/vue-the-mask
I recommend. Works perfectly with the examples below.
<el-input v-model="value" placeholder="12-1234" v-mask="'##-####'"/>

@matsuev
Copy link

matsuev commented May 16, 2018

Try this solution. Works for me

npm install inputmask --save

Then add to main.js

import Inputmask from 'inputmask'

Vue.directive('mask', {
    bind: function (el, binding) {
        Inputmask(binding.value).mask(el.getElementsByTagName('INPUT')[0])
    }
})

Use with <el-input>

<el-input
    v-model="phone.number"
    v-mask="'+7 (999) 999-9999'"
    placeholder="+7 (___) ___-____"
></el-input>

Inputmask usage https://github.com/RobinHerbots/Inputmask#usage

@thearabbit
Copy link
Author

Thanks for all, I would like to use mask with Currency/Money

@thearabbit
Copy link
Author

@matsuev, could example with currency formate, and unmask when get value?

@thearabbit
Copy link
Author

Now it work for unmask

import Inputmask from 'inputmask'
Vue.directive('inputmask', {
  bind: function(el, binding) {
    var inputs = el.getElementsByTagName('INPUT')
    var input = inputs[0]
    if (inputs.length > 1) {
      input = inputs[inputs.length - 1]
    }
    // new Inputmask(binding.value).mask(input)
    new Inputmask({
      autoUnmask: true,
    }).mask(input)
  },
})

Ex:

<el-input
      v-model="input"
      v-inputmask
      data-inputmask="'mask': '+7 (999) 999-9999'"
      placeholder="+7 (___) ___-____"
    />
    {{ inputJqMask }}

But now I am trying with currency

@thearabbit
Copy link
Author

but data-inputmask don't support object style

:data-inputmask="{mask: '+7 (999) 999-9999'}"

@2bj
Copy link

2bj commented Apr 10, 2019

I tried a lot of things with directives, but they were all with bugs (because el-input is wrapped around input). In the end, I decided to do it through computed values:

yarn add vue-imask
const maskField = (field, maskOptions) => {
    const mask = createMask(maskOptions)

    return {
        get() {
            return mask.resolve(this.form[field])
        },
        set(value) {
            this.form[field] = mask.resolve(value)
        }
    }
}

export default {
    data() {
        return {
            form: {phone: ''},
        }
    },
    computed: {
        phoneMasked: maskField('phone', {
            mask: '+{7} (000) 000-00-00'
        })
    }
}

p.s. #6 (comment) Fine solution, but not work on mobile devices

@ghost
Copy link

ghost commented Jun 23, 2019

Cause vue-inputmask doesnt work for el-input, I leaved as input and wrapped with <div class="el-input">
Example:

<el-form-item label="Date">
                            <div class="el-input">
                                <input v-model="formModel.date"
                                    name="date"                                   
                                    class="el-input__inner"
                                    validateevent="true"
                                    v-mask="{
                                        'mask': '99/99/9999'                                            
                                    }"/>                            
                            </div>                            
                        </el-form-item>

Also added validateevent="true"
image

@siberiadev
Copy link

Try this solution. Works for me

npm install inputmask --save

Then add to main.js

import Inputmask from 'inputmask'

Vue.directive('mask', {
    bind: function (el, binding) {
        Inputmask(binding.value).mask(el.getElementsByTagName('INPUT')[0])
    }
})

Use with

<el-input
    v-model="phone.number"
    v-mask="'+7 (999) 999-9999'"
    placeholder="+7 (___) ___-____"
></el-input>

Inputmask usage https://github.com/RobinHerbots/Inputmask#usage

I get this error when use your code:
TypeError: Cannot read property 'nodeType' of null

@Maksio
Copy link

Maksio commented Jun 24, 2021

I've found one more solution:

<el-input v-model="inputMask"></el-input>
<input type="hidden" v-model="inputMask" v-mask="'99/99/9999'">

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants