Commits

Anonymous committed 324a7c0

basic javascript complete

git-svn-id: http://svn.opensymphony.com/svn/webwork/trunk@389573baa09-0c28-0410-bef9-dab3c582ae83

  • Participants
  • Parent commits 2b3fc89

Comments (0)

Files changed (4)

File src/java/com/opensymphony/webwork/validators/JavaScriptEmailValidator.java

         StringBuffer js = new StringBuffer();
 
         js.append("value = form.elements['" + field + "'].value;\n");
-        js.append("if (value == \"\") {\n");
+        //
+        js.append("if (!value.match(/\\b(^(\\S+@).+((\\.com)|(\\.net)|(\\.org)|(\\.info)|(\\.edu)|(\\.mil)|(\\.gov)|(\\.biz)|(\\.ws)|(\\.us)|(\\.tv)|(\\.cc)|(\\..{2,2}))$)\\b/gi)) {\n");
         js.append("\talert('" + getMessage(null) + "');\n");
         js.append("\treturn '" + field + "';\n");
         js.append("}\n");

File src/java/com/opensymphony/webwork/validators/JavaScriptURLValidator.java

 
 public class JavaScriptURLValidator extends URLValidator implements ScriptValidationAware {
     public String validationScript(Map parameters) {
-        return "";
+        String field = (String) parameters.get("name");
+        StringBuffer js = new StringBuffer();
+
+        js.append("value = form.elements['" + field + "'].value;\n");
+        js.append("if (!value.match(/^(file|http):\\/\\/\\S+\\.(com|net|org|info|edu|mil|gov|biz|ws|us|tv|cc)$/i)) {\n");
+        js.append("\talert('" + getMessage(null) + "');\n");
+        js.append("\treturn '" + field + "';\n");
+        js.append("}\n");
+        js.append("\n");
+
+        return js.toString();
     }
 }

File src/java/template/xhtml/form-close.vm

         var focus = ${parameters.name}_validate_actual();
         if (focus != null) {
             form.elements[focus].focus();
+            if (form.elements[focus].type == 'text' || form.elements[focus].type == 'textarea') {
+                form.elements[focus].select();            
+            }
             return false;
         } else {
             return true;

File src/webapp/javascript-input.jsp

         <ww:form name="'test'" action="'javascriptValidation'" validate="true" >
             <ww:textfield label="'Required String'" name="'requiredString'" required="true"/>
             <ww:textfield label="'Some Int'" name="'intRange'" required="true"/>
-            <ww:textfield label="'Email'" name="'email'" required="true"/>
+            <ww:select label="'Email (select)" name="'email'" list="{'Select', 'foo@bar.com', 'baz@biz.com'}"/>
             <ww:textfield label="'URL'" name="'url'" required="true"/>
             <ww:textfield label="'Date'" name="'date'" required="true"/>
             <tr><td colspan="2"><hr/></td></tr>