mraible commented on code in PR #243:
URL: https://github.com/apache/roller/pull/243#discussion_r4574742607


##########
app/src/main/webapp/WEB-INF/jsps/core/CreateWeblog.jsp:
##########
@@ -89,6 +89,27 @@
     var saveButton;
 
     $( document ).ready(function() {
+       
+       jQuery("form.validate-form").validate();
+        // Added method to check valid email address and add a custom error 
message
+        jQuery.validator.addMethod(
+            "regex",
+            function(value, element, regexp)  {
+                if (regexp && regexp.constructor != RegExp) {
+                    regexp = new RegExp(regexp);
+                } else if (regexp.global) {
+                    regexp.lastIndex = 0;
+                }
+                return this.optional(element) || regexp.test(value);
+            }
+        );
+        // Applied email rules to field with class name validate-email
+        jQuery( ".validate-email" ).rules( "add", {
+            minlength: 3,
+            maxlength: 255,
+            email: true,
+            regex: /^\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b$/i

Review Comment:
   One more data point for this: `roller.js` already has a `validateEmail()` 
helper (around line 211) that `Register.jsp`, `Profile.jsp` and `UserEdit.jsp` 
use, and it accepts long TLDs. So today someone can register as 
`[email protected]` and then fail this check when creating a weblog. If 
the regex rule goes, `email: true` with `minlength` covers the same ground and 
keeps the two forms consistent.



##########
app/src/main/webapp/theme/scripts/roller.js:
##########
@@ -236,26 +236,4 @@ function actionErrors(html) {
     return Array.prototype.map.call(errors, function (error) {
         return error.textContent.trim();
     });
-}
-$(document).ready(function () {
-    jQuery("form.validate-form").validate();
-    // Added method to check valid email address and add a custom error message
-    jQuery.validator.addMethod(
-        "regex",
-        function(value, element, regexp)  {
-            if (regexp && regexp.constructor != RegExp) {
-                regexp = new RegExp(regexp);
-            } else if (regexp.global) {
-                regexp.lastIndex = 0;
-            }
-            return this.optional(element) || regexp.test(value);
-        }
-    );
-    // Applied email rules to field with class name validate-email
-    jQuery( ".validate-email" ).rules( "add", {
-        minlength: 3,
-        maxlength: 255,
-        email: true,
-        regex: /^\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b$/i
-    });
-});
+}

Review Comment:
   Optional, not for this PR: since `roller.js` also loads on public weblog 
pages, a guard around any page-specific setup that stays in here (for example, 
only running it when `window.jQuery && jQuery.validator` exist and 
`form.validate-form` is on the page) would stop this kind of error from coming 
back the next time a block is added.



##########
app/src/main/webapp/WEB-INF/jsps/core/CreateWeblog.jsp:
##########
@@ -89,6 +89,27 @@
     var saveButton;
 
     $( document ).ready(function() {
+       
+       jQuery("form.validate-form").validate();

Review Comment:
   Nit: these two lines have a tab and trailing whitespace, while the rest of 
the script uses 4-space indentation.
   
   ```suggestion
           jQuery("form.validate-form").validate();
   ```



##########
app/src/main/webapp/theme/scripts/roller.js:
##########
@@ -236,26 +236,4 @@ function actionErrors(html) {
     return Array.prototype.map.call(errors, function (error) {
         return error.textContent.trim();
     });
-}
-$(document).ready(function () {
-    jQuery("form.validate-form").validate();
-    // Added method to check valid email address and add a custom error message
-    jQuery.validator.addMethod(
-        "regex",
-        function(value, element, regexp)  {
-            if (regexp && regexp.constructor != RegExp) {
-                regexp = new RegExp(regexp);
-            } else if (regexp.global) {
-                regexp.lastIndex = 0;
-            }
-            return this.optional(element) || regexp.test(value);
-        }
-    );
-    // Applied email rules to field with class name validate-email
-    jQuery( ".validate-email" ).rules( "add", {
-        minlength: 3,
-        maxlength: 255,
-        email: true,
-        regex: /^\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b$/i
-    });
-});
+}

Review Comment:
   Nit: the file no longer ends with a newline.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to