Page 1 of 1

Form_CustomValidate code breaks modal lookups (v2023)

Posted: Fri Sep 13, 2024 9:58 pm
by philmills

Following the instructions given here
For trouble shooting i added this simple code to Add/Copy > Form_CustomValidate

function (fobj) { // DO NOT CHANGE THIS LINE! (except for adding "async" keyword)!

    if ($this->Parent_Name->FormValue=="123") {
        $this->Parent_Name->addErrorMessage("that's not a name"); // Add error message for the field
        return false;
    }
    return true;
}

It causes all of my modal lookups stop working as soon as the page loads

Why?

v2023


Re: Form_CustomValidate code breaks all modal lookups my form (v2023)

Posted: Sat Sep 14, 2024 2:50 am
by sticcino

your code is incorrect:

sample:

function(fobj) { // DO NOT CHANGE THIS LINE!
		var postalCode = fobj.x_addr_postal.value;
		var a_countryCode = fobj.x_addr_country.value;

		if(a_countryCode == 'CA') {            
			if(!postalFilter(postalCode)) {
				return this.addCustomError('addr_postal', "<?php echo JsEncode(str_replace("%s", 'Postal Code', 
				"Invalid Postal Code Format.<br>The postal code uses 18 alphabetic characters and 10 numeric characters.<br>Postal codes 
				do not include the letters D, F, I, O, Q or U, and the first position also does not make use of the letters W or Z.")) ?>");
			}    
		}
		
	return true;
}

Re: Form_CustomValidate code breaks modal lookups (v2023)

Posted: Sat Sep 14, 2024 10:26 am
by arbei

philmills wrote:

function (fobj) { // DO NOT CHANGE THIS LINE! (except for adding "async" keyword)!
if ($this->Parent_Name->FormValue=="123") {

You mixed up server side and client side Form_CustomValidate events.