The CreatorCon Call for Content is officially open! Get started here.

Catalog Client Script not working with g_form.showErrorBox

Sergio26
Giga Guru

Hello,

I have a catalog client script to validate a phone number format that looks like this.

It's an OnChange script applied for All UI types

function onChange(control, oldValue, newValue, isLoading) {

    if (isLoading || newValue == '') {

        return;

    }

    var pattern = /^\(\d{3}\)\s\d{3}-\d{4}$/; //(xxx) xxx-xxxx

    var phone = g_form.getValue('phone_number');

    if (!pattern.test(phone)) {

        phone = phone.replace(/\D/g, '');

        var regex = /^\d{10}$/;

        var is_valid = regex.test(phone);

		g_form.showErrorBox('phone_number', 'Invalid phone number. Please enter 10 digits');
        if (!is_valid) {

            g_form.addInfoMessage('Invalid phone number. Please enter 10 digits');
			//g_form.showErrorBox('phone_number', 'test');
            g_form.clearValue('phone_number');


        } else {

            phone = '(' + phone.slice(0, 3) + ') ' + phone.slice(3, 6) + '-' + phone.slice(6, 10);
            g_form.setValue('phone_number', phone);

        }

    }

}

The script works fine when I use the 'g_gorm.addInfoMessage' but when I use the 'g_form.showErrorBox' (commented in the script) it doesn't work and I don't understand why...

Anybody can help?

Thank you

1 ACCEPTED SOLUTION

Allen Andreas
Administrator
Administrator

Hi,

Have you checked both portal and back-end UI, just to see if it's showing back-end but not Portal?

I see where you said you had the UI Type set to ALL, but just curious if this is one of those "it works in back-end, but not portal, and I was only checking portal" type of scenarios? Haha.

Would you consider using show field message, but of error type?

g_form.showFieldMsg('phone_number', 'Invalid phone number. Please enter 10 digits', 'error');

Don't forget, you'd also want to code for removing that as well with "hideFieldMsg".

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

3 REPLIES 3

Allen Andreas
Administrator
Administrator

Hi,

Have you checked both portal and back-end UI, just to see if it's showing back-end but not Portal?

I see where you said you had the UI Type set to ALL, but just curious if this is one of those "it works in back-end, but not portal, and I was only checking portal" type of scenarios? Haha.

Would you consider using show field message, but of error type?

g_form.showFieldMsg('phone_number', 'Invalid phone number. Please enter 10 digits', 'error');

Don't forget, you'd also want to code for removing that as well with "hideFieldMsg".

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Thank you. Now it work!

Tanushree Doiph
Mega Guru

Hey,

Try without using single quote on test

g_form.showErrorBox('phone_number', test);

OR

Use this --> g_form.showFieldMsg("phone_number","This is the error","error");

 

Please mark correct and helpful.

Thanks

Tanushree