Bug 704879 - (6/6) Show form validation message when invalid element is focused. r=lucasr
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Tue, 06 Mar 2012 11:56:44 -0800
changeset 88399 f0d2d132bb7e71ede804b6aeb6099e36663fe111
parent 88398 a979f7ffdba1926e38467b7a79c9cf216cfee0b6
child 88400 35056a47d906a3488c309fd586e913330da93059
push id22194
push usermak77@bonardo.net
push dateWed, 07 Mar 2012 09:33:54 +0000
treeherdermozilla-central@8ef88a69f861 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslucasr
bugs704879
milestone13.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 704879 - (6/6) Show form validation message when invalid element is focused. r=lucasr
mobile/android/chrome/content/browser.js
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -2841,25 +2841,28 @@ var FormAssistant = {
   // Keep track of whether or not an invalid form has been submitted
   _invalidSubmit: false,
 
   init: function() {
     Services.obs.addObserver(this, "FormAssist:AutoComplete", false);
     Services.obs.addObserver(this, "FormAssist:Hidden", false);
     Services.obs.addObserver(this, "invalidformsubmit", false);
 
+    // We need to use a capturing listener for focus events
+    BrowserApp.deck.addEventListener("focus", this, true);
     BrowserApp.deck.addEventListener("input", this, false);
     BrowserApp.deck.addEventListener("pageshow", this, false);
   },
 
   uninit: function() {
     Services.obs.removeObserver(this, "FormAssist:AutoComplete");
     Services.obs.removeObserver(this, "FormAssist:Hidden");
     Services.obs.removeObserver(this, "invalidformsubmit");
 
+    BrowserApp.deck.removeEventListener("focus", this);
     BrowserApp.deck.removeEventListener("input", this);
     BrowserApp.deck.removeEventListener("pageshow", this);
   },
 
   observe: function(aSubject, aTopic, aData) {
     switch (aTopic) {
       case "FormAssist:AutoComplete":
         if (!this._currentInputElement)
@@ -2882,25 +2885,30 @@ var FormAssistant = {
 
     // Ignore this notificaiton if the current tab doesn't contain the invalid form
     if (BrowserApp.selectedBrowser.contentDocument !=
         aFormElement.ownerDocument.defaultView.top.document)
       return;
 
     this._invalidSubmit = true;
 
+    // Our focus listener will show the element's validation message
     let currentElement = aInvalidElements.queryElementAt(0, Ci.nsISupports);
-    if (this._showValidationMessage(currentElement))
-      currentElement.focus();
+    currentElement.focus();
   },
 
   handleEvent: function(aEvent) {
     switch (aEvent.type) {
+      case "focus":
+        let currentElement = aEvent.target;
+        this._showValidationMessage(currentElement);
+        break;
+
       case "input":
-        let currentElement = aEvent.target;
+        currentElement = aEvent.target;
 
         // Since we can only show one popup at a time, prioritze autocomplete
         // suggestions over a form validation message
         if (this._showAutoCompleteSuggestions(currentElement))
           break;
         if (this._showValidationMessage(currentElement))
           break;