From 6cf9f96d51e1d601acdc37e9f1b214fc1d848444 Mon Sep 17 00:00:00 2001 From: Michael Tozzo Date: Sun, 4 Sep 2016 22:58:56 -0400 Subject: [PATCH] Adds a "Disable HTML5 Validation" feature. --- source/chrome/html/overlay/overlay.html | 5 +- source/chrome/javascript/overlay/forms.js | 16 +++++ source/chrome/locales/en_US/messages.json | 3 + source/common/javascript/features/forms.js | 58 +++++++++++++++++++ source/firefox/javascript/overlay/forms.js | 6 ++ .../firefox/locales/en-US/overlay/overlay.dtd | 2 + .../locales/en-US/overlay/overlay.properties | 4 ++ source/firefox/xul/overlay/menus/forms.xul | 2 + source/firefox/xul/overlay/overlay.xul | 1 + 9 files changed, 95 insertions(+), 2 deletions(-) diff --git a/source/chrome/html/overlay/overlay.html b/source/chrome/html/overlay/overlay.html index de92f50..c308794 100644 --- a/source/chrome/html/overlay/overlay.html +++ b/source/chrome/html/overlay/overlay.html @@ -89,24 +89,25 @@
  • +
  • diff --git a/source/chrome/javascript/overlay/forms.js b/source/chrome/javascript/overlay/forms.js index 9fd7f3c..9998f65 100644 --- a/source/chrome/javascript/overlay/forms.js +++ b/source/chrome/javascript/overlay/forms.js @@ -23,6 +23,7 @@ $(function() $("#remove-maximum-lengths").append(WebDeveloper.Locales.getString("removeMaximumLengths")).on("click", WebDeveloper.Overlay.Forms.removeMaximumLengths); $("#uncheck-all-checkboxes").append(WebDeveloper.Locales.getString("uncheckAllCheckboxes")).on("click", WebDeveloper.Overlay.Forms.uncheckAllCheckboxes); $("#view-form-information").append(WebDeveloper.Locales.getString("viewFormInformation")).on("click", WebDeveloper.Overlay.Forms.viewFormInformation); + $("#disable-form-validation").append(WebDeveloper.Locales.getString("disableFormValidation")).on("click", WebDeveloper.Overlay.Forms.disableFormValidation); }); // Adds a feature on a tab @@ -298,3 +299,18 @@ WebDeveloper.Overlay.Forms.viewFormInformation = function() } }); }; + +// Disables HTML5 validation +WebDeveloper.Overlay.Forms.disableFormValidation = function() +{ + var featureItem = $(this); + + WebDeveloper.Overlay.getSelectedTab(function(tab) + { + // If the tab is valid + if(WebDeveloper.Overlay.isValidTab(tab)) + { + WebDeveloper.Overlay.Forms.addFeatureOnTab(featureItem, tab, "WebDeveloper.Forms.disableFormValidation([document]);"); + } + }); +}; diff --git a/source/chrome/locales/en_US/messages.json b/source/chrome/locales/en_US/messages.json index c3d01db..e0a1e67 100644 --- a/source/chrome/locales/en_US/messages.json +++ b/source/chrome/locales/en_US/messages.json @@ -124,6 +124,9 @@ "removeMaximumLengths": { "message": "Remove Maximum Lengths" }, "uncheckAllCheckboxes": { "message": "Uncheck All Checkboxes" }, "viewFormInformation": { "message": "View Form Information" }, + "disableFormValidation": { "message": "Disable HTML5 Validation" }, + "disableFormValidationSingleResult": { "message": "1 validation element was disabled." }, + "disableFormValidationMultipleResult": { "message": "$count$ validation elements were disabled.", "placeholders": { "count": { "content": "$1" } } }, "disableImages": { "message": "Disable Images" }, "displayAltAttributes": { "message": "Display Alt Attributes" }, diff --git a/source/common/javascript/features/forms.js b/source/common/javascript/features/forms.js index aec70a0..08003ec 100644 --- a/source/common/javascript/features/forms.js +++ b/source/common/javascript/features/forms.js @@ -1019,3 +1019,61 @@ WebDeveloper.Forms.toggleCheckboxes = function(check, documents) } } }; + +// Removes all HTML5 validation properties +WebDeveloper.Forms.disableFormValidation = function(documents) +{ + var attributeElements = null; + var inputTypeElements = null; + var validationRemovedElements = 0; + + for(var i = 0, l = documents.length; i < l; i++) + { + attributeElements = documents[i].querySelectorAll("[required], [pattern], [min], [max]"); + + for(var j = 0, m = attributeElements.length; j < m; j++) + { + if(attributeElements[j].hasAttribute("required")) + { + attributeElements[j].removeAttribute("required"); + validationRemovedElements++; + } + + if(attributeElements[j].hasAttribute("pattern")) + { + attributeElements[j].removeAttribute("pattern"); + validationRemovedElements++; + } + + if(attributeElements[j].hasAttribute("min")) + { + attributeElements[j].removeAttribute("min"); + validationRemovedElements++; + } + + if(attributeElements[j].hasAttribute("max")) + { + attributeElements[j].removeAttribute("max"); + validationRemovedElements++; + } + } + + inputTypeElements = documents[i].querySelectorAll("input[type=email], input[type=url], input[type=number], input[type=range]"); + + for(var k = 0, n = inputTypeElements.length; k < n; k++) + { + inputTypeElements[k].type = "text"; + + validationRemovedElements++; + } + } + + if(validationRemovedElements == 1) + { + WebDeveloper.Common.displayNotification("disableFormValidationSingleResult"); + } + else + { + WebDeveloper.Common.displayNotification("disableFormValidationMultipleResult", [validationRemovedElements]); + } +}; diff --git a/source/firefox/javascript/overlay/forms.js b/source/firefox/javascript/overlay/forms.js index ab61091..433bf29 100644 --- a/source/firefox/javascript/overlay/forms.js +++ b/source/firefox/javascript/overlay/forms.js @@ -117,3 +117,9 @@ WebDeveloper.Overlay.Forms.viewFormInformation = function() { WebDeveloper.Overlay.openGeneratedTab(WebDeveloper.Common.getChromeURL("generated/view-form-information.html"), WebDeveloper.Content.getForms(), WebDeveloper.Overlay.Forms.getViewFormInformationLocale()); }; + +// Disables HTML5 validation on all form fields +WebDeveloper.Overlay.Forms.disableFormValidation = function() +{ + WebDeveloper.Forms.disableFormValidation(WebDeveloper.Content.getDocuments(WebDeveloper.Common.getContentWindow())); +}; diff --git a/source/firefox/locales/en-US/overlay/overlay.dtd b/source/firefox/locales/en-US/overlay/overlay.dtd index cbe9219..de04e60 100644 --- a/source/firefox/locales/en-US/overlay/overlay.dtd +++ b/source/firefox/locales/en-US/overlay/overlay.dtd @@ -182,6 +182,8 @@ + + diff --git a/source/firefox/locales/en-US/overlay/overlay.properties b/source/firefox/locales/en-US/overlay/overlay.properties index 49f8ee2..c78043c 100644 --- a/source/firefox/locales/en-US/overlay/overlay.properties +++ b/source/firefox/locales/en-US/overlay/overlay.properties @@ -335,3 +335,7 @@ responsiveLayouts=Responsive Layouts # View Source With viewSourceWith=View Source With + +# Make Form Fields Writable +disableFormValidationMultipleResult=%S validation elements were disabled. +disableFormValidationSingleResult=1 validation element was disabled. diff --git a/source/firefox/xul/overlay/menus/forms.xul b/source/firefox/xul/overlay/menus/forms.xul index 7deb19f..03b4925 100644 --- a/source/firefox/xul/overlay/menus/forms.xul +++ b/source/firefox/xul/overlay/menus/forms.xul @@ -29,4 +29,6 @@ + + diff --git a/source/firefox/xul/overlay/overlay.xul b/source/firefox/xul/overlay/overlay.xul index e2d3d7f..4a863b0 100644 --- a/source/firefox/xul/overlay/overlay.xul +++ b/source/firefox/xul/overlay/overlay.xul @@ -83,6 +83,7 @@ +