Click event of view model being called on page load

2 posts, 0 answers
  1. Thomas
    Thomas avatar
    5 posts
    Member since:
    Nov 2013

    Posted 04 Dec 2013 Link to this post

    I have this view, as below, which is bound the viewModel/module shown below (loaded up via requirejs as per the KendoUI Mobile Music Store).  When I load the page, the authenticate is being called (i.e., it's making that ajax network call as well).
    <div data-role="view" id="login-view" data-layout="blank"
        <h1 style="text-align: center;">Title</h1>
        <form id="login">
            <input data-bind="value: username" id="username" type="text" placeholder="Username" /><br />
            <input data-bind="value: password" id="password" type="password" placeholder="Password" /><br />
            <input type="submit" value="Login" data-bind="click: authenticate" />
    define(["jQuery", "kendo", "modernizr", "app/environment"], function ($, kendo, modernizr, environment) {
        var authenticate = function (username, password) {
            return $.ajax({
                url: environment.apiConnection + '/canlogin?userid=' + username + '&password=' + password,
                type: 'get',
                dataType: 'jsonp'
        authenticate().done(function (data) {
        }).fail(function() {
        return {
            viewModel: kendo.observable({
                username: null,
                password: null,
                authenticate: function () {
                    var username = this.get('username'),
                        password = this.get('password');
                    authenticate(username, password);
                    if (!Modernizr.localstorage) {
                        alert('There was an error accessing LocalStorage on this device.');
                    localStorage["username"] = username;
                    localStorage["password"] = password;
  2. Thomas
    Thomas avatar
    5 posts
    Member since:
    Nov 2013

    Posted 05 Dec 2013 Link to this post

    The issue was due to using an <input type=submit>.  Changing this to a <button> fixed the problem.
Back to Top