Forums de discussion

Form field validator should only work if only 1 (of 3) submits are pressed

Lee Chamberlain, modifié il y a 7 années.

Form field validator should only work if only 1 (of 3) submits are pressed

Junior Member Publications: 92 Date d'inscription: 05/05/16 Publications récentes
I've a form which current has three possible submit options

Submit
Change
Reject

I've one particular field which needs to be validated only if the submit button is pressed (it's not relevent if change or reject is hit).

I've tried to tailor my validation so it only validates when the script to submit is used, however it's validating on all three buttons.

Can anyone see where I've gone wrong?

Thanks


<script type="text/javascript">



$("#submitCart").click(function() {


	AUI().use('aui-form-validator', function(A) {	
		
		var rules = {
				<portlet:namespace />cartNumber: {
		        required: true
		      }
			};
		      
		var fieldStrings = {
				<portlet:namespace />cartNumber: {
		        required: 'Cart Number is a required field'
		      }
		    };  
		
		new A.FormValidator(
		      {
		        boundingBox: '#<portlet:namespace />updateCartForm',
		        fieldStrings: fieldStrings,
		        rules: rules,
		        showAllMessages: true
		      }
			
		);
	})
	
AUI().use('aui-base', function(A) {
	

A.one('#<portlet:namespace />updateCartForm').set('action','<%= submitCart.toString() %>');
});

});

</script>



<script type="text/javascript">

$("#changeCart").click(function() {
AUI().use('aui-base', function(A) {
A.one('#<portlet:namespace />updateCartForm').set('action','<%= changeCart.toString() %>');
});
//$("#<portlet:namespace />updateCartForm").submit();
});

</script>


<script type="text/javascript">

$("#deleteOrder").click(function() {
AUI().use('aui-base', function(A) {
A.one('#<portlet:namespace />updateCartForm').set('action','<%= deleteCart.toString() %>');
});
//$("#<portlet:namespace />updateCartForm").submit();
});

</script>