Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remember Password with AngularJS and ng-submit

Tags:

How do I get the browser to ask the user to remember the password when using ng-submit in an AngularJS single page application.

My Form:

<form action="/#/dashboard/login" onsubmit="return false;" ng-submit="login()" name="loginForm">
    <input type="text" required id="username" name="username" ng-model="username" autocomplete="on" placeholder="Username" value="">
    <input type="password" required id="password" name="password" ng-model="password" autocomplete="on" placeholder="Password" value="">
    <button type="submit" class="btn">Submit</button>
</form>

Any Ideas?


UPDATE

I just added the action to get the browser to recognise the form and trick it into remembering the password. (which obviously didn't work.) The form works fine without the action. The onsubmit="return false;" prevents the execution of the action. Only the ng-submit is doing anything.

like image 618
soelu Avatar asked Sep 03 '13 07:09

soelu


2 Answers

Your code is ok, but you need to add the name attributes to your inputfields, such as:

<input type="text" name="username" ...>

and

<input type="password" name="password" ...>
like image 68
SiCN Avatar answered Sep 19 '22 15:09

SiCN


The problem is the dynamically generated login form. After putting the form into the index.html it worked as expected. I guess this is a security issue.

The problem that then occurred was that the ngModels didn't get updated on autofill. After some searching I found the solution to that problem here. In AngularJS 1.2+ this is supposed to be fixed.

like image 26
soelu Avatar answered Sep 22 '22 15:09

soelu