Pre-populated default value

sparkles
Tera Contributor

Hello, I have a single line txt type field that allow user to enter the name of the new group they want to create. Our stander format for group name start with "EY - group name " Ideally we want the field to pre-populated with CA- and then we need some way to ensure the user actually provide a name for the group, so that they don’t just submit requests saying group name is just "EY - ".

Any idea how to get this done?

 

Thanks,

S

 

1 ACCEPTED SOLUTION

anshul_goyal
Kilo Sage

Hello @sparkles,

1. Client Script (onLoad) — Prepopulate the field

Create a Client Script:

  • Type: onLoad

  • Script:

function onLoad() {
    var groupField = g_form.getValue('group_name'); // replace with actual field name
    if (!groupField) {
        g_form.setValue('group_name', 'CA - ');
    }
}

 

2. Client Script (onSubmit) — Validate group name

Create another Client Script:

  • Type: onSubmit

  • Script:

function onSubmit() {
    var groupName = g_form.getValue('group_name').trim();

    // Check if it starts with "CA - " and has something after
    if (groupName === 'CA -') {
        alert('Please enter a valid group name after "CA -".');
        return false;
    }

    // Optional: You can also enforce a regex to ensure more robust validation
    var regex = /^CA -\s*\S+/;
    if (!regex.test(groupName)) {
        alert('Group name must start with "CA - " followed by a valid name.');
        return false;
    }

    return true;
}


Please mark my response as Accepted and Helpful for future references.

Thanks

View solution in original post

4 REPLIES 4

anshul_goyal
Kilo Sage

Hello @sparkles,

1. Client Script (onLoad) — Prepopulate the field

Create a Client Script:

  • Type: onLoad

  • Script:

function onLoad() {
    var groupField = g_form.getValue('group_name'); // replace with actual field name
    if (!groupField) {
        g_form.setValue('group_name', 'CA - ');
    }
}

 

2. Client Script (onSubmit) — Validate group name

Create another Client Script:

  • Type: onSubmit

  • Script:

function onSubmit() {
    var groupName = g_form.getValue('group_name').trim();

    // Check if it starts with "CA - " and has something after
    if (groupName === 'CA -') {
        alert('Please enter a valid group name after "CA -".');
        return false;
    }

    // Optional: You can also enforce a regex to ensure more robust validation
    var regex = /^CA -\s*\S+/;
    if (!regex.test(groupName)) {
        alert('Group name must start with "CA - " followed by a valid name.');
        return false;
    }

    return true;
}


Please mark my response as Accepted and Helpful for future references.

Thanks

Thanks @anshul_goyal it works!!

@sparkles Thanks for marking my solution!

Shraddha Kadam
Mega Sage

Hello @sparkles ,

 

In the field Default value of the variable, use "CA - " 

ShraddhaKadam_1-1753189456243.png

 

ShraddhaKadam_0-1753189423530.png

 

Just a thought - There's a chance users might remove "CA-" and only enter the group name. So, when you create the group where your logic is stored, why not automatically prepend "CA- + <variable_value>?

If my response was helpful, please mark it as correct and helpful.
Thank you.