roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adityasha...@apache.org
Subject [roller] 02/02: Implemented: logic to apply email validations (ROL-2156) Added method to apply regular expression and added rules to validate email Added error message with internationalised text instead of hard coded text Removed existing custom code to validate inputs
Date Sun, 31 May 2020 13:51:30 GMT
This is an automated email from the ASF dual-hosted git repository.

adityasharma pushed a commit to branch roller-6.0.x
in repository https://gitbox.apache.org/repos/asf/roller.git

commit 46abbd7f52e839cbb2ae8d2fc8e28598e7f8e585
Author: Aditya Sharma <iamadityasharma7@gmail.com>
AuthorDate: Sun May 31 18:08:42 2020 +0530

    Implemented: logic to apply email validations (ROL-2156)
    Added method to apply regular expression and added rules to validate email
    Added error message with internationalised text instead of hard coded text
    Removed existing custom code to validate inputs
---
 .../main/resources/ApplicationResources.properties |  9 +++---
 .../main/webapp/WEB-INF/jsps/core/CreateWeblog.jsp | 33 ++++------------------
 app/src/main/webapp/theme/scripts/roller.js        | 19 +++++++++++++
 3 files changed, 29 insertions(+), 32 deletions(-)

diff --git a/app/src/main/resources/ApplicationResources.properties b/app/src/main/resources/ApplicationResources.properties
index 2673f6e..0c315a0 100644
--- a/app/src/main/resources/ApplicationResources.properties
+++ b/app/src/main/resources/ApplicationResources.properties
@@ -418,6 +418,7 @@ CreateWeblog.error.descriptionSize=Description cannot be more than 255
character
 CreateWeblog.error.emailAddressNull=Email address is a required field
 CreateWeblog.error.emailAddressSize=Email address cannot be more than 255 characters
 CreateWeblog.error.emailAddressBad=The email address you entered is not properly formatted
+CreateWeblog.error.emailAddressInvalid=Please enter a valid email address
 CreateWeblog.error.localeNull=Locale is a required field
 CreateWeblog.error.localeSize=Locale cannot be more than 8 characters
 CreateWeblog.error.timeZoneNull=Time Zone is a required field
@@ -442,7 +443,7 @@ email.comment.title=Comment
 email.comment.moderate.title=Pending Blog Comment
 email.comment.commentApproved=Comment Approved
 
-#---------------------------------------------------------------- Error messages 
+#---------------------------------------------------------------- Error messages
 
 error.untranslated={0}
 
@@ -537,7 +538,7 @@ can have multiple weblogs and each Roller weblog can have multiple \
 authors.
 index.createWeblogBy=Create your first weblog via the 
 index.createWeblogPage=New Weblog Creation Page
-   
+
 index.setFrontpage=Designate a frontpage weblog
 index.setFrontpageHelp=\
 You must specify a weblog to serve as the front page weblog, you can do this \
@@ -1619,7 +1620,7 @@ Entry.error.categoryNull=Category is required field
 Entry.error.textNull=Content is a required field
 
 
-# -------------------------------------------------------- Weblog entries Pager 
+# -------------------------------------------------------- Weblog entries Pager
 
 weblogEntriesPager.latest.home=Main
 weblogEntriesPager.latest.next=Next page
@@ -1646,7 +1647,7 @@ weblogEntriesPager.month.nextCollection=Next month ({0})
 weblogEntriesPager.month.prevCollection=Previous month ({0})
 weblogEntriesPager.month.dateFormat=MMM yyyy
 
-# ---------------------------------------------------------- Weblog Entry Remove 
+# ---------------------------------------------------------- Weblog Entry Remove
 
 weblogEntryRemove.removeWeblogEntry=Delete Weblog Entry
 weblogEntryRemove.areYouSure=Are you sure you want to delete this Weblog Entry?
diff --git a/app/src/main/webapp/WEB-INF/jsps/core/CreateWeblog.jsp b/app/src/main/webapp/WEB-INF/jsps/core/CreateWeblog.jsp
index 0f8762e..48c4f08 100644
--- a/app/src/main/webapp/WEB-INF/jsps/core/CreateWeblog.jsp
+++ b/app/src/main/webapp/WEB-INF/jsps/core/CreateWeblog.jsp
@@ -26,13 +26,13 @@
     <s:hidden name="salt"/>
 
     <s:textfield label="%{getText('generic.name')}"
-                 tooltip="%{getText('createWebsite.tip.name')}" onkeyup="formChanged()"
-                 name="bean.name" size="30" maxlength="30" requiredLabel="Name is a required
field" required="required"/>
+                 tooltip="%{getText('createWebsite.tip.name')}"
+                 name="bean.name" size="30" maxlength="30" data-msg-required="%{getText('CreateWeblog.error.nameNull')}"
required="required"/>
 
     <s:textfield label="%{getText('createWebsite.handle')}"
                  tooltip="%{getText('createWebsite.tip.handle')}"
                  name="bean.handle" size="30" maxlength="30"
-                 onkeyup="handlePreview(this)" requiredLabel="Handle is a required field"
required="required"/>
+                 onkeyup="handlePreview(this)" data-msg-required="%{getText('CreateWeblog.error.handleNull')}"
required="required"/>
 
     <div class="form-group">
         <label class="col-sm-3"></label>
@@ -47,8 +47,8 @@
         </div>
     </div>
 
-    <s:textfield label="%{getText('createWebsite.emailAddress')}"
-                 tooltip="%{getText('createWebsite.tip.email')}" onkeyup="formChanged()"
+    <s:textfield label="%{getText('createWebsite.emailAddress')}" cssClass="validate-email"
data-msg="%{getText('CreateWeblog.error.emailAddressInvalid')}"
+                 tooltip="%{getText('createWebsite.tip.email')}" data-msg-required="%{getText('CreateWeblog.error.emailAddressNull')}"
required="required"
                  name="bean.emailAddress" size="40" maxlength="50"/>
 
     <s:select label="%{getText('createWebsite.locale')}"
@@ -99,29 +99,8 @@
         previewImage('<s:property value="bean.theme"/>');
         </s:else>
 
-        // TODO Remove custom validation code
-        // formChanged()
     });
 
-    function formChanged() {
-        // TODO Remove custom validation code
-        /*var valid = false;
-
-        var name   = $("#createWeblog_bean_name:first").val();
-        var handle = $("#createWeblog_bean_handle:first").val();
-        var email  = $("#createWeblog_bean_emailAddress:first").val();
-
-        valid = !!(name && name.trim().length > 0
-            && handle && handle.trim().length > 0
-            && email && email.trim().length > 0 && validateEmail(email));
-
-        if ( valid ) {
-            saveButton.attr("disabled", false);
-        } else {
-            saveButton.attr("disabled", true);
-        }*/
-    }
-
     function handlePreview(handle) {
         previewSpan = document.getElementById("handlePreview");
         var n1 = previewSpan.childNodes[0];
@@ -140,8 +119,6 @@
                 $('#themeThumbnail').attr('src','<s:property value="siteURL" />' +
data.previewPath);
             }
         });
-        formChanged();
     }
 
 </script>
-
diff --git a/app/src/main/webapp/theme/scripts/roller.js b/app/src/main/webapp/theme/scripts/roller.js
index a85adcf..298a799 100644
--- a/app/src/main/webapp/theme/scripts/roller.js
+++ b/app/src/main/webapp/theme/scripts/roller.js
@@ -212,4 +212,23 @@ function validateEmail(email) {
 }
 $(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
+    });
 });


Mime
View raw message