How to validate the form onsubmit through widget

vijayakumar kon
Tera Contributor
In server script I used the regular expression to validate the email. If it is not valid I am using below one to show the error message in client controller.
It is working fine when we click some where in the form it will clear the value and show the error message. 
The problem is if the user fill all the details and at the end he provide the wrong mail id and directly click on submit it is accepting to raise the request.
 
How to do validation on submit with out using the DOM. Can any one help me on this
 
var c = this;
    $scope.onLoad = function() {
        c.server.update().then(function(res) {

            $rootScope.$on("field.change", function(evt, parms) {
                //  $scope.page.g_form.hideFieldMsg('guest_email_address');
                if (parms.field.name == 'guest_email_address') {


                    $scope.emailcheck();

                 
                }
            });
        });
    };

    $scope.emailcheck = function() {
        c.server.get({
            action: 'emailcheck',
            mail: $scope.page.g_form.getValue("guest_email_address")
        }).then(function(response) {
 
if (response.data.mail == 'notvalid') {

 

                $scope.page.g_form.setValue('guest_email_address', '');
                $scope.page.g_form.showFieldMsg('guest_email_address', 'Not a valid mail Id', 'error');
}
 
 
0 REPLIES 0