Show alert onSubmit if field is empty and user should not able to submit the request from portal.

varma2
Mega Sage

Hi All,

We have two choice variable if user not selected any of them it show trigger a alert message and prevent for submission.

user should not able to submit without selecting those choice variable.

 

Thanks,

Varma 

 

1 ACCEPTED SOLUTION

Then you can check and abort only if both are empty, like so:

function onSubmit() {
    if (g_form.getValue('your variable1') == '' && g_form.getValue('your variable2') == '') {
        g_form.addErrorMessage('Fields can not be empty');
        return false;
    }
}

View solution in original post

4 REPLIES 4

Jaspal Singh
Mega Patron
Mega Patron

Hi,

 

In your onSubmit() client script you can check for values & if it is empty then you need to use return false; to abort the action.

For eg.

function onSubmit()
{
 if(g_form.getValue('field1')=='') //missed an extra roundbracket
{
 return false;//abort action
}
}

Willem
Giga Sage
Giga Sage

Hi Varma,

 

Please try like this:

Replace your variable1 and 2 with your variable name

function onSubmit() {
    if (g_form.getValue('your variable1') == '' || g_form.getValue('your variable2') == '') {
        g_form.addErrorMessage('Fields can not be empty');
        return false;
    }
}

Hi Willem, Thanks for reply

 

What if user need to select any one of the variable like variable1 or varible2.

 

Thanks,

Varma

Then you can check and abort only if both are empty, like so:

function onSubmit() {
    if (g_form.getValue('your variable1') == '' && g_form.getValue('your variable2') == '') {
        g_form.addErrorMessage('Fields can not be empty');
        return false;
    }
}