jQuery validation without "Client-Side Validation"

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
Chris
User
Posts: 162

jQuery validation without "Client-Side Validation"

Post 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;
}


Webmaster
User
Posts: 9438

Post 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
}


Chris
User
Posts: 162

Post 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?


Webmaster
User
Posts: 9438

Post by Webmaster »

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


Chris
User
Posts: 162

Post 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") );
}
});
}


Webmaster
User
Posts: 9438

Post by Webmaster »

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


Chris
User
Posts: 162

Post by Chris »

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


Post Reply