Salome HOME
Validation of the screens' input fields are implemented.
[tools/siman.git] / Workspace / Siman / WebContent / study / newStudy.jsp
index 7fada946e6fd08c1f39864fcd492be8186658557..1d0148a26352825ef6794790bc4369ba63a9b699 100644 (file)
                create.projectContextId.value = <s:property value="projectContextId"/>;
         </s:if>
                setValue();
+               
+               //Studied product validation (based on struts-generated validation)
+           //relies on javascript included by 'validate="true"' for displaying error messages
+           document.getElementById("create").addEventListener('submit', function(event) {   //cross-browser solution
+               form = document.getElementById("create");
+       
+               var errors = false;
+               var continueValidation = true;
+                       
+               // field name: product
+               // custom validation function
+               if (form.elements['projectContext'] && form.elements['projectContextId']) {
+                   field = form.elements['projectContext'];
+                   id = form.elements['projectContextId'];
+                   var error = "The field \'Studied product\' must be filled";
+                   if (continueValidation
+                           && id.value != null && (
+                               (id.value == 0
+                                  && field.value != null 
+                                  && (field.value == "" || field.value.replace(/^\s+|\s+$/g,"").length == 0)
+                               )
+                               || id.value == -1
+                           )
+                       ) {
+                       addError(field, error);
+                       errors = true;
+                   }
+               }
+               if(errors) {
+                   event.preventDefault();    //cross-browser solution
+               }
+           });
+           
+           function setDefaultSelection()(event) {
+            tds = document.getElementById("select");
+            tde = document.getElementById("enter");
+            tds.style.display = "block"; // Hides the select input
+            tde.style.display = "none"; // Displays the text input
+            
+               create.projectContextId.value = -1;
+               create.projectContextId.focus();
+               
+               //hide back button
+           }
        });
+    
+    
 </script>
 
 <!-- New study dialog
                <s:text name="title.newstudy" />
        </div>
        <div id="top-spacer"></div>
-       <form id="create" name="create"
-               action="<tiles:getAsString name="input_action"/>" method="post">
-               <table class="text">
+       <s:form id="create" name="create"
+               action="%{#request.valid_action}" method="post" validate="true" cssClass="text">
 
                        <tr class="error">
                                <td colspan="3"><s:text name="%{error}" /></td>
                        </tr>
 
                        <tr>
-                               <td>&nbsp;<s:text name="field.studytitle" />*:&nbsp;
+                               <td>&nbsp;<s:text name="field.studytitle" />:&nbsp;<span class="error">*</span>
                                </td>
                                <td><s:textfield theme="simple" size="60" name="title" /></td>
                        </tr>
 
                        <tr>
-                               <td>&nbsp;<s:text name="field.product" />*:&nbsp;
+                               <td>&nbsp;<s:text name="field.product" />:&nbsp;<span class="error">*</span>
                                </td>
                                <s:if test="projectContextValues.size > 0">
                                        <td id="select"><select name="projectContextId"
 
                        <tr>
                                <td align="right" colspan="2"><s:submit
-                                               action="%{#request.valid_action}" theme="simple" type="button"
+                                               theme="simple" type="button"
                                                key="button.newstudy" /></td>
                        </tr>
 
-               </table>
-       </form>
+       </s:form>
        <div id="top-spacer"></div>
 </div>