title: Using reactjs and javascript - Chrome does not offer to remember passwords
body: <p>Hi I ran into the bug where Chrome does not offer to remember userid &amp; passwords. </p>
  
  <p>I tried the solution in link below but I could not get it to work. Has anybody solved this for React? 
  <a href="http://code.google.com/p/chromium/issues/detail?id=43219">http://code.google.com/p/chromium/issues/detail?id=43219</a></p>
  
  <p>I implemented the solution in the above link but it did nothing when using react.</p>
  
  <p>Many Thanks!</p>
  
  <p><strong>Sample Code as requested:</strong>
  The original workaround is described in the link above - I have included here:
  This is a Chrome bug and here is the recommended workaround:
  <a href="http://code.google.com/p/chromium/issues/detail?id=43219">http://code.google.com/p/chromium/issues/detail?id=43219</a></p>
  
  <p>As a followup to comment #5, here is a fuller explanation of a workaround that I have tested.
  On your login page, include a form with two input elements. Set the name and id of one to "userid" and the other to "password". E.g.,</p>
  
  <pre><code>&lt;input value type="text" id="userid" name="userid" autocomplete="on"&gt;
  &lt;input value type="password" id="password" name="password" autocomplete="on"&gt;
  </code></pre>
  
  <p>Give the form a POST action to a blank html page served from the same domain, say blank.html. Set the onsubmit handler to a JavaScript function:</p>
  
  <pre><code>&lt;form name="login" id="login" method="POST" action="blank.html" onsubmit="return do_login();"&gt;
  </code></pre>
  
  <p>Above the form, include a hidden iframe element, like so:</p>
  
  <pre><code>&lt;iframe src="login.html" style="width:0px;height:0px;border:0px;" id="hidden" name="hidden"&gt;          &lt;/iframe&gt;
  </code></pre>
  
  <p>The login.html file must also be served from the same domain, and it should contain an identical form (same names and ids, same action and method) as the one on the real login form.
  In your JavaScript do_login handler, perform the authentication however you like. To get Chrome to prompt the user to store the password, have the JavaScript code copy the values from the real form to the hidden form, then submit the hidden form, like so:</p>
  
  <pre><code>var userid = document.getElementById("userid").value;
  var password = document.getElementById("password").value; 
  var iframe = document.getElementById("hidden");
  var iframedoc = iframe.contentWindow ? iframe.contentWindow.document : iframe.contentDocument;
  var fake_login_form = iframedoc.getElementById("login");
  var fake_userid = iframedoc.getElementById("userid");
  fake_userid.value = userid;
  fake_password.value = password;
  fake_login_form.submit();
  </code></pre>
  
  <p>Tested with Chrome 10.0.648.204.</p>
  
  <p><strong>Here is what I did for React:</strong></p>
  
  <p>I created a 'blank form' and configured an nginx rule:
      
      
        
          
          
        
        
          
        
      </p>
  
  <p>Included a dummy login form which is rendered and hidden:
  <strong>Note: I am using react-frame-component</strong>
      /**
       * @jsx React.DOM
       */</p>
  
  <pre><code>'use strict';
  
  var React = require('react/addons');
  var Frame = require('react-frame-component');
  var Input = require('react-bootstrap/Input');
  
  
  var DummyLoginForm = React.createClass({
  
      _onChange: function(){
          console.log('DummyLoginForm onChange called')
      },
  
      _onSubmit: function() {
          console.log('DummyLoginForm onsubmit called');
  
          var email = this.refs.userid.getValue();
          var password = this.refs.password.getValue();
  
          console.log(email);
          console.log(password);
      },
  
      render: function () {
          var content = ( 
          &lt;div&gt;
              &lt;Frame id="hidden" width="0" height="0" name="hidden"&gt;
                 &lt;form role="form" name="dummylogin" id="dummylogin" ref="dummylogin" method="POST" action="/login/index.html" onsubmit="return _onSubmit();"&gt;
                      &lt;input value type="text" id="userid" name="userid" ref="userid" autoComplete="on" onChange={this._onChange}/&gt;
                      &lt;input value type="password" id="password" name="password" autoComplete="on" onChange={this._onChange}/&gt;
                  &lt;/form&gt;
              &lt;/Frame&gt;
          &lt;/div&gt;
  
          );
  
          return content;
      }
  
    /*jshint ignore:end */
  </code></pre>
  
  <p>});</p>
  
  <pre><code>module.exports = DummyLoginForm;
  </code></pre>
  
  <p><strong>In the real login modal I do this:</strong>
  <strong>I am using react-bootstrap modal</strong></p>
  
  <pre><code>onSubmit: function(e) {
      if(e &amp;&amp; typeof e !== 'undefined') {
          e.stopPropagation();
          e.preventDefault();
          }
          var email = this.refs.email.getValue();
          var password = this.refs.password.getValue();
  
      MyUtils.login(email, password);
  
      // workaround to force chrome to prompt to save password details 
      if(BrowserUtils.isChrome()) {
  
          console.log("Chrome");
  
          var iframe = document.getElementById("hidden");
          var iframedoc = iframe.contentWindow ? iframe.contentWindow.document :  iframe.contentDocument;
          var fake_login_form = iframedoc.getElementById("dummylogin");
          var fake_userid = iframedoc.getElementById("userid");
          var fake_password = iframedoc.getElementById("password");
          fake_userid.value = email;
          fake_password.value = password;
          fake_login_form.submit();
      }
  
  },
  </code></pre>
  
  <p><strong>The _onSubmit: function() in DummyLoginForm does not get triggered</strong></p>