Onsubmit client script

Mark Wood
Tera Contributor

Hello Team,

I have implemented the validation for the update set naming convention, and everything is working fine. However, when a user submits the form with a name that does not follow the convention, the validation message appears but disappears within a second.

I would like the message to remain visible for at least 10 seconds to ensure the user has enough time to read it. How can I achieve this?

I have attached my onLoad and onSubmit client scripts for reference.

 

Onload Client Script:

function onLoad() {
 
var fn=g_user.firstName;
var ln=g_user.lastName;
var fv=fn.charAt(0);
var fv2=ln.charAt(0);

if(g_form.isNewRecord())
{
    g_form.setValue('name',"PN-"+fv+fv2+"-"+"STR");
}
   
}

 

onSubmit client script

function onSubmit() {
 
    var name = g_form.getValue('name');
alert("Onsubmit"+name);
    // Define the required pattern: <Project Prefix>-<User Initials>-<Story>
    var pattern =/^[A-Z]{2,3}-[A-Z]{2}-STR\d+$/;
 
 
 
    if (!pattern.test(name)) {
        g_form.addErrorMessage("Invalid Update Set name! Follow the naming convention: Project Prefix-User Initials-Story(e.g., FN-MI-STR00011)");
        location.reload();
        return false;
       
    }
   
}

 

1 ACCEPTED SOLUTION

Hi @Mark Wood 
Then just use the same logic in the OnSubmit client script instead of reloading the form.

function onSubmit() {

    var name = g_form.getValue('name');
    alert("Onsubmit" + name);
    // Define the required pattern: <Project Prefix>-<User Initials>-<Story>
    var pattern = /^[A-Z]{2,3}-[A-Z]{2}-STR\d+$/;

    if (!pattern.test(name)) {
        g_form.addErrorMessage("Invalid Update Set name! Follow the naming convention: Project Prefix-User Initials-Story(e.g., FN-MI-STR00011)");
        setTimeout(function() {
			g_form.clearValue("name");
			g_form.clearMessages();

            var fn = g_user.firstName;
            var ln = g_user.lastName;
            var fv = fn.charAt(0);
            var fv2 = ln.charAt(0);

            if (g_form.isNewRecord()) {
                g_form.setValue('name', "PN-" + fv + fv2 + "-" + "STR");
            }

        }, 10000);
        return false;


    }

}

View solution in original post

10 REPLIES 10

this should be the ideal way to check it