0

My View:

<div class="register-box">
        <p class="register-title">Login</p>
        <form autocomplete="on">
            <label class="input-label">
                <span>Email</span>
                <input name="email" type="email" placeholder="Email" pattern=".{5,30}" required title="5 to 30 characters" data-bind="value: email" />
            </label>
            <label class="input-label">
                <span>Password</span>
                <input name="password" type="password" placeholder="Password" pattern=".{5,20}" required title="5 to 20 characters"  data-bind="value: password"/>
            </label>
            <div class="button-area">
                <label><input type="checkbox" name="checkbox" value="value" data-bind="checked: rememberMe">Remember Me</label>
                <a data-bind="click: login"class="btn btn-success">Login <i class="fa fa-arrow-right"></i></a>
            </div>
        </form>
    </div>

my viewmodel:

var vm = {};

// properties
vm.email = ko.observable();
vm.password = ko.observable();
vm.rememberMe = ko.observable(true);

// actions
vm.login = function () {
    var payload = {
        username: vm.email(),
        password: vm.password(),
        rememberMe: vm.rememberMe()
    }
    accountService.login(payload, function() {
        app.isAuthenticated(true);
        router.navigate('admin');
    });
}

return vm;

Despite using <form> and typed elements, no browser ever asks me to save the password when I log in. What am I doing wrong?

RobVious
  • 12,685
  • 25
  • 99
  • 181
  • 2
    Because you are doing an ajax request, browsers only ask for you to save the info when you do an actual form submit – Patrick Evans Oct 05 '14 at 16:39
  • @PatrickEvans Is there anyway to 'hijack' this behavior so I can develop with MVVM/SPA patterns AND leverage browser features like this? – RobVious Oct 05 '14 at 16:48
  • There are some work arounds like [this](http://stackoverflow.com/questions/2382329/how-can-i-get-browser-to-prompt-to-save-password) but i do not think there is reliable a cross browser way. – Patrick Evans Oct 05 '14 at 16:54
  • You could have two ways of handling the login from the same form. If the user wants to save the password in the browser you could post the form, otherwise use AJAX. Once the password is saved it will be filled in by the browser the next time the user starts to fill in the form, and you can use the AJAX method. – Guffa Oct 05 '14 at 16:56

0 Answers0