I am still trying to find a comfortable way to do things with NS. Moved from JS to TS (classes are more clear), and I pretend to use models and inheritance all that I can.
For starters I have a login form with such controls as these:
<TextField id="{{txtUser}}" class="input" hint="Email" keyboardType="email" autocorrect="false" autocapitalizationType="none" returnKeyType="next" returnPress="focusPassword()"></TextField>
...
<TextField id="{{txtPassword}}" class="input" hint="Password" secure="true" returnKeyType="done"></TextField>
....
<Button text="Log In" tap="{{onsubmit}}" class="btn btn-primary m-t-20"></Button>
Then the view model goes below… I can’t see to reach the values in the Textfields… i get undefined… Any pointer on what may be going on?
(BTW, CoreModel is an observable descendant that I made hoping to add some stuff to be shared across models, like loggedIn status)
import * as view from "tns-core-modules/ui/core/view";
import { topmost } from "ui/frame";
import { Page } from "ui/page";
import { CoreModel } from "~/shared/core-model";
export class LoginViewModel extends CoreModel {
constructor() {
super();
// login form controls variables
this.set("txtUser", "usuario");
this.set("txtPwd", "");
}
onsubmit(args) {
const page = <Page>args.object;
// GRAB variables in form
this.set("txtUser",view.getViewById(page, "txtUser"));
this.set("txtPwd", view.getViewById(page, "txtPassword"));
alert(this.get("txtUser"));
alert(view.getViewById(page, "txtPassword"));
// TODO: Validation against db
this.loggedIn = true;
// Back Home
topmost().navigate({moduleName: "home/home-page", clearHistory: true});
}