Get value from textfield


#1

Hello,
I’m a beginner in native script.
I made a login page and when I click in the submit button I want to get the user value in the textfield pseudo and password.
But I don’t know how to make that.
This is my code :

<Page>
<StackLayout>
    <StackLayout>
            <TextField id="pseudo"></TextField>
    </StackLayout>

    <StackLayout>
            <TextField  id="password"></TextField>
    </StackLayout>

    <Button (tap)="login()"></Button>
</StackLayout>
</Page>

Could you help me please ?
Cordially


#2

Are you using Angular / Core? If it’s core your syntax for tap event is wrong. If it’s Angular, you don’t have to include Page element, its created automatically when you use page router outlet.

I suggest you to go though the respective getting started guide.


#3

I use angular and native script with typescript language.
Ok for the Page, I will change that.
But the problem is not resolve.
Could you see me a simple example because I search since a week to find a solution but I don’t find ?
Cordially


#4

If you know how to do this in Angular, it’s just the same with NativeScript. Use noModel / FormGroup / simply assign angular id and use ViewChild directive to get the element and it’s value from there.


#6

No, you can’t use document.getelementById(), that’s not a Angular api but browser specific.

Besides getViewById() is an equivalent to getelementById() in NativeScript environment.


#8

You can use Page.getViewById(“pseudo”).text, if you haven’t gone through the getting started guide yet, I would encourage you to do that at earliest to get some heads up on basics.