Note that there are some explanatory texts on larger screens.

plurals
  1. POstruts2 jquery ajax and client side validatio not working toghether
    primarykey
    data
    text
    <p>I have used standard code snippet from <a href="http://struts.jgeppert.com/struts2-jquery-showcase/index.action" rel="nofollow">http://struts.jgeppert.com/struts2-jquery-showcase/index.action</a> and <a href="http://code.google.com/p/struts2-jquery/wiki/Validation" rel="nofollow">http://code.google.com/p/struts2-jquery/wiki/Validation</a>.</p> <p>But the client side and ajax server side validations are not working together.</p> <p>The problem is form submission does not stop and action gets called even if we <code>preventDefault</code> or do anything else.</p> <pre><code>&lt;%@ taglib prefix="s" uri="/struts-tags"%&gt; &lt;%@ taglib prefix="sj" uri="/struts-jquery-tags"%&gt; &lt;html&gt; &lt;head&gt; &lt;sj:head jqueryui="true"/&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="result"&gt; &lt;s:actionerror/&gt; &lt;s:fielderror fieldName="name" value="eroor"&gt;&lt;/s:fielderror&gt; Submit form bellow.&lt;/div&gt; &lt;!-- A List for Global Error Messages --&gt; &lt;ul id="formerrors" class="errorMessage"&gt;&lt;/ul&gt; &lt;s:form id="formValidateCustom" action="register1.action" namespace="/" theme="simple" cssClass="yform" &gt; &lt;fieldset&gt; &lt;legend&gt;AJAX Form with Validation&lt;/legend&gt; &lt;div class="type-text"&gt; &lt;label for="echo"&gt;User: &lt;span id="loginuserError"&gt;&lt;/span&gt;&lt;/label&gt; &lt;sj:textfield id="name" name="name" /&gt; &lt;/div&gt; &lt;div class="type-text"&gt; &lt;label for="echo"&gt;Password: &lt;span id="loginpasswordError"&gt;&lt;/span&gt;&lt;/label&gt; &lt;sj:textfield id="password" name="password" /&gt; &lt;/div&gt; &lt;div class="type-button"&gt; &lt;sj:submit targets="result" button="true" validate="true" validateFunction="customeValidation" value="Submit" onBeforeTopics="before" timeout="2500" indicator="indicator" /&gt; &lt;/div&gt; &lt;/fieldset&gt; &lt;/s:form&gt; &lt;script type="text/javascript"&gt; function customeValidation(form, errors) { //List for errors // alert("in js"); var list = $('#formerrors'); //Handle non field errors if (errors.errors) { $.each(errors.errors, function(index, value) { list.append('&lt;li&gt;'+value+'&lt;/li&gt;\n'); }); } //Handle field errors if (errors.fieldErrors) { $.each(errors.fieldErrors, function(index, value) { var elem = $('#'+index); if(elem) { alert(value[0]); } }); } } $.subscribe('before', function(event,data) { var fData = event.originalEvent.formData; alert('About to submit: \n\n' + fData[0].value + ' to target '+event.originalEvent.options.target+' with timeout '+event.originalEvent.options.timeout ); var form = event.originalEvent.form[0]; if (form.name.value.length &lt; 2) { alert('Please enter a value with min 2 characters'); **// the event does not stop here if we use ajax validation i.e validate = true, if we remove it then this works.** event.originalEvent.options.submit = false; } }); &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>the event.originalEvenet.options.submit = false does not stop here if we use ajax validation i.e validate = true in submit button, if we remove it then this works.**</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload