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

Usage with NativeScript-Vue #29

Open
sougiovn opened this issue Nov 8, 2018 · 26 comments
Open

Usage with NativeScript-Vue #29

sougiovn opened this issue Nov 8, 2018 · 26 comments

Comments

@sougiovn
Copy link

sougiovn commented Nov 8, 2018

I'm new to NativeScript and I'm starting with Vue, how do I use it with NativeScript-Vue?

I tested like this, but got no result

<template>
  <Page 
    xmlns="http://schemas.nativescript.org/tns.xsd" 
    xmlns:mtf="nativescript-masked-text-field">
    <mtf:MaskedTextField v-model="cpf" />
  </Page>
</template>
@PeterStaev
Copy link
Owner

Hey @gigioSouza , sadly I'm not a Vue developer so i cannot help you on this. I think best to ask on SO so you can get more audience and an appropriate answer.

@gab0gomes
Copy link

Hi,

you need to register the component in your main.js file

Vue.registerElement('MaskedTextField',
    () => require('nativescript-masked-text-field').MaskedTextField
);

then, use in your vue component

<MaskedTextField
    v-model="cpf"
    mask="999.999.999-99"
    keyboardType="phone"
/>

@sougiovn
Copy link
Author

@Gabrielr2508 It "worked", the app compiled and I'm able to use the MaskedTextField tag/component, but the mask isn't applied.

@gab0gomes
Copy link

@gigioSouza The mask works here, but v-model doesn't. Can't figure out why not. :(

@gab0gomes
Copy link

@gigioSouza The mask works here, but v-model doesn't. Can't figure out why not. :(

I tried to bind the "text" property of the field and update it in the textchange event, but this caused me to not be able to change the text in the emulator

@lennonphosfato
Copy link

I was able to get the value using a refs property and in function it retrieves the value this way $ refs.refName.nativeView.text

@kfvit-andreaskviby
Copy link

Hey
When I try to use this component in my NativeScript Vue app I get the error

JS ERROR TypeError: Could not load view for: maskedtextfield. TypeError: view_1.CSSType is not a function. (In 'view_1.CSSType("MaskedTextField")', 'view_1.CSSType' is undefined)

I have registered the component using

Vue.registerElement('MaskedTextField',
    () => require('nativescript-masked-text-field').MaskedTextField
);

Then I just add it to the page and when I do I get the error.

<MaskedTextField
                                        v-model="email"
                                        mask="999.999.999-99"
                                        keyboardType="phone"
                                />

I am super new to Vue and Nativescript som I have no idea what I do wrong.

@PeterStaev
Copy link
Owner

@andreaskvibydialect , make sure you are using Nativescript 4 or later. The CSSType was added relatively recent 😃

@kfvit-andreaskviby
Copy link

@andreaskvibydialect , make sure you are using Nativescript 4 or later. The CSSType was added relatively recent 😃

Hey
Sorry for being a novice but do you mean tns-core-modules?

@PeterStaev
Copy link
Owner

@andreaskvibydialect , make sure you are using Nativescript 4 or later. The CSSType was added relatively recent 😃

Hey
Sorry for being a novice but do you mean tns-core-modules?

That is correct.

@kfvit-andreaskviby
Copy link

@andreaskvibydialect , make sure you are using Nativescript 4 or later. The CSSType was added relatively recent 😃

Hey
Sorry for being a novice but do you mean tns-core-modules?

That is correct.

Hey
I have version 5.2.0 when I run tns --version now and still I can't make it work in my app. Any other ideas of my registration is wrong of if it has to be locally referenced or in some way.

@PeterStaev
Copy link
Owner

PeterStaev commented Feb 25, 2019

I have version 5.2.0 when I run tns --version now and still I can't make it work in my app. Any other ideas of my registration is wrong of if it has to be locally referenced or in some way.

Sadly I'm not a Vue developer so can't help much with the registration and other Vue stuff...

@kfvit-andreaskviby
Copy link

I have version 5.2.0 when I run tns --version now and still I can't make it work in my app. Any other ideas of my registration is wrong of if it has to be locally referenced or in some way.

Sadly I'm not a Vue developer so can't help much with the registration and other Vue stuff...

I understand, me neither but if you hear or see some NativeScript-Vue App that makes it possible to get this component to work please let me know.

@prinzt
Copy link

prinzt commented Feb 25, 2019

Hey
When I try to use this component in my NativeScript Vue app I get the error

JS ERROR TypeError: Could not load view for: maskedtextfield. TypeError: view_1.CSSType is not a function. (In 'view_1.CSSType("MaskedTextField")', 'view_1.CSSType' is undefined)

I have registered the component using

Vue.registerElement('MaskedTextField',
    () => require('nativescript-masked-text-field').MaskedTextField
);

Then I just add it to the page and when I do I get the error.

<MaskedTextField
                                        v-model="email"
                                        mask="999.999.999-99"
                                        keyboardType="phone"
                                />

I am super new to Vue and Nativescript som I have no idea what I do wrong.

Try the following:
Remove the "platforms" folder and start "tns run ..." again.

I just tried the package and it worked.

@budi7
Copy link

budi7 commented May 16, 2019

I have version 5.2.0 when I run tns --version now and still I can't make it work in my app. Any other ideas of my registration is wrong of if it has to be locally referenced or in some way.

Sadly I'm not a Vue developer so can't help much with the registration and other Vue stuff...

I understand, me neither but if you hear or see some NativeScript-Vue App that makes it possible to get this component to work please let me know.

hei i got this plugin working on vue nativescript

this on my main.js
Vue.registerElement('MaskedTextField', () => require('nativescript-masked-text-field').MaskedTextField)

this on my component page
<MaskedTextField mask="999.999.999" keyboardType="phone" />

and who still use ns-vue 1.3.1 version, u should to edit your package.json
"tns-core-modules": "~4.0.0", // i changed to v 4.0.0, previously its 3.*.*

then run npm run clean
do npm install --save

finally npm run watch:android or ios and it should work

Screen Shot 2019-05-16 at 11 42 38

hope that helps :)

@seergiue
Copy link

v-model doesn't seem to work, anyone with same behaviour and how to fix it?

@Jonarod
Copy link

Jonarod commented May 31, 2019

The textfield is not even showing up for me (tns 5.3.4)...

@kfvit-andreaskviby
Copy link

kfvit-andreaskviby commented May 31, 2019 via email

@bundyo
Copy link

bundyo commented May 31, 2019

In order for v-model to work, you will need to specify which property/event to use, like this:

Vue.registerElement(
    'MaskedTextField',
    () => require('nativescript-masked-text-field').MaskedTextField,
    {
        model: {
            prop: 'text',
            event: 'textChange'
        }
    }
);

Check this example:

https://play.nativescript.org/?template=play-vue&id=3Rac7h&v=3

@Jonarod
Copy link

Jonarod commented May 31, 2019

@bundyo helped me out from th slack forum. Now it works.
However, I found the origin of the plugin not showing was because I was actually registering the component twice: once like suggested by @bundyo :

Vue.registerElement(
    'MaskedTextField',
    () => require('nativescript-masked-text-field').MaskedTextField,
    {
        model: {
            prop: 'text',
            event: 'textChange'
        }
    }
);

but then also in my component.vue:
DON'T DO THIS

<template>
    <MaskedTextField mask="99/99" v-model="expiryDate" />
</template>

<script>
import {MaskedTextField} from "nativescript-masked-text-field"  // REMOVE THIS

export default {
    components: {MaskedTextField}, // REMOVE THIS
    data(){
        return {
            expiryDate: ''
        }
    }
}
</script>

@MohammedBashiru
Copy link

@Jonarod Thanks that helped once again.

@andresilva-cc
Copy link

andresilva-cc commented Aug 26, 2019

Even with @bundyo answer it is still not working for me.
Binding text property doesn't return anything in data. When I use with v-model it binds a whole object (not just the value) but I can't type in the field (tried with both virtual and physical keyboard).

@Nayeb-karimi
Copy link

How to add v-model to this.

@andresilva-cc
Copy link

I ended up using ref and obtaining the value through this.$refs.refName.nativeView.text, as suggested by @lennonphosfato

@keithgulbro
Copy link

keithgulbro commented Feb 4, 2020

I ended up using the following code snippet to workaround the v-model issue:

<MaskedTextField
      mask="(999) 999-9999"
      keyboardType="phone"
      ref="maskedtextfield"
      @textChange="textFieldChange($event)"
    />

data() {
    return {
        val: null
    }
},
methods:{
    textFieldChange(args) {
      this.val = args.value;
    }
}

Hopefully this helps!

@Dartow
Copy link

Dartow commented Jan 2, 2021

Hi,

I am getting this error when trying to load the app with MaskedTextField. Did the same as suggested by @bundyo.

TypeError: Class constructor TextField cannot be invoked without 'new'

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

No branches or pull requests