Page 1 of 1

jQuery validation without "Client-Side Validation"

Posted: Sat Oct 05, 2013 12:36 am
by Chris

Hi, it seems the client scripts don't fire if I have only PHP validation on required fields. How do we enable our own validation in Form_CustomValidate without enabling the built-in Javascript validation?

If I enable it, I can use this function to validate my form with jQuery validate no problem, but it get added on TOP of the existing validation. I want to combine my own js validation with the server-side PHP validation on required etc fields.

function(fobj) { // DO NOT CHANGE THIS LINE!
// Your custom validation code here, return false if invalid.
var form = $("form#fdemosadd");
form.validate({
rules: { //
x_demo_owner: { required: true },
x_demo_filename: { required: true },
x_demo_slated: { required: true }
}
});
if (form.valid()) return true;
}


Re: jQuery validation without "Client-Side Validation"

Posted: Sat Oct 05, 2013 10:04 am
by Webmaster

Just use Client Script for the page (see Server Events and Client Scripts in the help file) to override the generated Valdiate method with your own, e.g. (v10)

fdemosadd.Validate = function() { // assume table name is "demos" and the page is Add page
// your own validation
}


Re: jQuery validation without "Client-Side Validation"

Posted: Sun Oct 06, 2013 11:17 pm
by Chris

OK this works great, but I have to click twice on the Add button in order to trigger the validation. The first click doesn't do anything.

Do you know the reason for that?


Re: jQuery validation without "Client-Side Validation"

Posted: Mon Oct 07, 2013 9:14 am
by Webmaster

Can't guess from the limited info. Post your code. Set breakpoints in your code and debug it in your browser.


Re: jQuery validation without "Client-Side Validation"

Posted: Tue Oct 15, 2013 10:03 pm
by Chris

Here is my exact function for validating the demos "Add" table. It works correctly, but I need to submit twice before it fires. It is currently in Table-Specific -> Add/Copy Page -> Client Script.

// Write your client script here, no need to add script tags.
fdemosadd.Validate = function() {
$("#fdemosadd").validate({
rules: { //
x_demo_owner: { required: true },
x_demo_filename: { required: true },
x_demo_slated: { required: true }
},
errorPlacement: function(error, element) {
error.insertAfter( element.closest("span") );
}
});
}


Re: jQuery validation without "Client-Side Validation"

Posted: Thu Oct 17, 2013 9:54 am
by Webmaster

Your function must return true if validation passes and vice versa, refer to the original function as example.


Re: jQuery validation without "Client-Side Validation"

Posted: Thu Oct 17, 2013 2:47 pm
by Chris

OK thanks returning true makes the validation work properly, and I can customize the operation, thanks!