hide error message

KaMmILa__
Tera Expert

We have 4 fields in which only 1 field should be entered for example if the user provides value in GIft and then enter project ,we have a client script on change where it will clear the gift value and show an error message like below, but it will still show the error message , how to clear that , 

FYI : we have 4 onchange client scripts when the filed value changes, it will clear the values in the other fields and display the error message. (the error messages are bit confusing to user) 

 

find_real_file.png

1 ACCEPTED SOLUTION

Hitoshi Ozawa
Giga Sage
Giga Sage

Created 4 variables named "gift", "grant", "designated", and "project".

1. Client Script onChange on "gift"

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var fieldName = 'gift';
    var columnNameList = ['gift', 'grant', 'designated', 'project'];
    var sum = 0;
    for (var i = 0; i < columnNameList.length; i++) {
        sum += g_form.getValue(columnNameList[i]).length ? 1 : 0;
    }
    if (sum > 1) {
        g_form.showFieldMsg(fieldName, 'Only one of the following is required: Gift, Grant, Desginated, Project. Please enter a value for jsut one of these fields', 'error');
        for (var j = 0; j < columnNameList.length; j++) {
            if (columnNameList[j] != fieldName) {
                g_form.hideFieldMsg(columnNameList[j]);
            }
        }
    }
}

2. Client Script onChange on "grant"

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var fieldName = 'grant';
    var columnNameList = ['gift', 'grant', 'designated', 'project'];
    var sum = 0;
    for (var i = 0; i < columnNameList.length; i++) {
        sum += g_form.getValue(columnNameList[i]).length ? 1 : 0;
    }
    if (sum > 1) {
        g_form.showFieldMsg('grant', 'Only one of the following is required: Gift, Grant, Desginated, Project. Please enter a value for jsut one of these fields', 'error');
        for (var j = 0; j < columnNameList.length; j++) {
            if (columnNameList[j] != fieldName) {
                g_form.hideFieldMsg(columnNameList[j]);
            }
        }
    }
}

3. Client Script onChange on "designated"

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var fieldName = 'designated';
    var columnNameList = ['gift', 'grant', 'designated', 'project'];
    var sum = 0;
    for (var i = 0; i < columnNameList.length; i++) {
        sum += g_form.getValue(columnNameList[i]).length ? 1 : 0;
    }
    if (sum > 1) {
        g_form.showFieldMsg(fieldName, 'Only one of the following is required: Gift, Grant, Desginated, Project. Please enter a value for jsut one of these fields', 'error');
        for (var j = 0; j < columnNameList.length; j++) {
            if (columnNameList[j] != fieldName) {
                g_form.hideFieldMsg(columnNameList[j]);
            }
        }
    }
}

4. Client Script onChange on "project"

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var fieldName = 'project';
    var columnNameList = ['gift', 'grant', 'designated', 'project'];
    var sum = 0;
    for (var i = 0; i < columnNameList.length; i++) {
        sum += g_form.getValue(columnNameList[i]).length ? 1 : 0;
    }
    if (sum > 1) {
        g_form.showFieldMsg(fieldName, 'Only one of the following is required: Gift, Grant, Desginated, Project. Please enter a value for jsut one of these fields', 'error');
        for (var j = 0; j < columnNameList.length; j++) {
            if (columnNameList[j] != fieldName) {
                g_form.hideFieldMsg(columnNameList[j]);
            }
        }
    }
}

Execution result:

1. Enter Gift

find_real_file.png

2. Enter Designated

find_real_file.png

3. Enter Project

find_real_file.png

View solution in original post

2 REPLIES 2

bammar
Kilo Sage
Kilo Sage

These seem like informational messages- why not use these as help text- and you have the option- Always expanded- this way you dont have to fight with all of these client scripts. 

If you must keep the client scripts- then you may have to add the line of code to clear the other 3 values on change just in case they have anything in them- but you have to do it for each script- add the clearing of the other 3 errors. 

Hitoshi Ozawa
Giga Sage
Giga Sage

Created 4 variables named "gift", "grant", "designated", and "project".

1. Client Script onChange on "gift"

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var fieldName = 'gift';
    var columnNameList = ['gift', 'grant', 'designated', 'project'];
    var sum = 0;
    for (var i = 0; i < columnNameList.length; i++) {
        sum += g_form.getValue(columnNameList[i]).length ? 1 : 0;
    }
    if (sum > 1) {
        g_form.showFieldMsg(fieldName, 'Only one of the following is required: Gift, Grant, Desginated, Project. Please enter a value for jsut one of these fields', 'error');
        for (var j = 0; j < columnNameList.length; j++) {
            if (columnNameList[j] != fieldName) {
                g_form.hideFieldMsg(columnNameList[j]);
            }
        }
    }
}

2. Client Script onChange on "grant"

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var fieldName = 'grant';
    var columnNameList = ['gift', 'grant', 'designated', 'project'];
    var sum = 0;
    for (var i = 0; i < columnNameList.length; i++) {
        sum += g_form.getValue(columnNameList[i]).length ? 1 : 0;
    }
    if (sum > 1) {
        g_form.showFieldMsg('grant', 'Only one of the following is required: Gift, Grant, Desginated, Project. Please enter a value for jsut one of these fields', 'error');
        for (var j = 0; j < columnNameList.length; j++) {
            if (columnNameList[j] != fieldName) {
                g_form.hideFieldMsg(columnNameList[j]);
            }
        }
    }
}

3. Client Script onChange on "designated"

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var fieldName = 'designated';
    var columnNameList = ['gift', 'grant', 'designated', 'project'];
    var sum = 0;
    for (var i = 0; i < columnNameList.length; i++) {
        sum += g_form.getValue(columnNameList[i]).length ? 1 : 0;
    }
    if (sum > 1) {
        g_form.showFieldMsg(fieldName, 'Only one of the following is required: Gift, Grant, Desginated, Project. Please enter a value for jsut one of these fields', 'error');
        for (var j = 0; j < columnNameList.length; j++) {
            if (columnNameList[j] != fieldName) {
                g_form.hideFieldMsg(columnNameList[j]);
            }
        }
    }
}

4. Client Script onChange on "project"

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var fieldName = 'project';
    var columnNameList = ['gift', 'grant', 'designated', 'project'];
    var sum = 0;
    for (var i = 0; i < columnNameList.length; i++) {
        sum += g_form.getValue(columnNameList[i]).length ? 1 : 0;
    }
    if (sum > 1) {
        g_form.showFieldMsg(fieldName, 'Only one of the following is required: Gift, Grant, Desginated, Project. Please enter a value for jsut one of these fields', 'error');
        for (var j = 0; j < columnNameList.length; j++) {
            if (columnNameList[j] != fieldName) {
                g_form.hideFieldMsg(columnNameList[j]);
            }
        }
    }
}

Execution result:

1. Enter Gift

find_real_file.png

2. Enter Designated

find_real_file.png

3. Enter Project

find_real_file.png