Input check at onSubmit /Implemented with Client Script

user_ms
Tera Expert

Only one error message is displayed at onSubmit.
When I resolve one error, another error appears.
If there is an error in two items, I want to display the error messages for both items at the same time at onSubmit.
Please let me know if you know how.

1 ACCEPTED SOLUTION

@user_ms Here is the updated script, it will hold the form submission until the error is corrected.

 

function onSubmit() {
    g_form.clearMessages();
    var fieldArray = ['test1', 'test2'];
    var regex = /^[0-9]+$/;
	var errorCount= 0;
    for (var i = 0; i < fieldArray.length; i++) {
        if (!regex.test(g_form.getValue(fieldArray[i]))) {
            g_form.showFieldMsg(fieldArray[i], 'error!', 'error');
			errorCount++;
        }

    }

    if(errorCount==0){
		return true;
	}
	else{
		return false;
	}
}

View solution in original post

6 REPLIES 6

Sandeep Rajput
Tera Patron
Tera Patron

@user_ms Here is the script you should use to show error messages for both the fields.

 

function onSubmit() {
	g_form.clearMessages();
    var fieldArray = ['test1', 'test2'];
    var regex = /^[0-9]+$/;
    for (var i = 0; i < fieldArray.length; i++) {
        if (!regex.test(g_form.getValue(fieldArray[i]))){						
			g_form.showErrorBox(fieldArray[i], 'error');			
		}			
            
    }
}

@user_ms Do you have any further questions on this topic. If not then please accept the answer as correct solution.

@Sandeep Rajput 

Thank you for your answer.

I tried the method you taught me.

 

I added "return false" to the source, but after fixing the error I can't submit.
I would like to be unable to submit unless I correct the error.

 

The error message has been changed to below.

g_form.showFieldMsg('test1', 'error!', 'error');

 

I would like to add the following error checking.(as test3,test4)

var regex2 = /^[\uFF61-\uFF9F\d_+*]+$/;

 


Do you know how to solve it?

@user_ms Here is the updated script, it will hold the form submission until the error is corrected.

 

function onSubmit() {
    g_form.clearMessages();
    var fieldArray = ['test1', 'test2'];
    var regex = /^[0-9]+$/;
	var errorCount= 0;
    for (var i = 0; i < fieldArray.length; i++) {
        if (!regex.test(g_form.getValue(fieldArray[i]))) {
            g_form.showFieldMsg(fieldArray[i], 'error!', 'error');
			errorCount++;
        }

    }

    if(errorCount==0){
		return true;
	}
	else{
		return false;
	}
}