nuna's avatar
Level 1

How to do a success popup if the validateFormAdd is true?

$(document).ready( function(){
    $('.brand-form-validation').on('click', function(e) {
        e.preventDefault();      
        validateFormAdd('add_brand').done(function(response){
            if (response.status == true) {
                showToastr('Created', 'Tag Created Successfully!', 'success');
            }else {
                showToastr('Unsuccessful', 'Tag could not be Created!', 'info');
            }
        }
    });

    $('#add_brand').keyup( function(e) {
        e.preventDefault();      
        validateFormAdd('add_brand');
    });

});

The function for the validate form

function validateFormAdd(formName) {
    $("#"+formName).validate({
      rules: {
        name: {
            required: true,
            maxlength: 100,
        },
        store_id: {
            required: true,
        },
        code: {
            required: true,
            maxlength: 100,
        },
        description: {
            maxlength: 255,
        },
      },
    });
  }
0 likes
3 replies
bobbybouwmann's avatar

You can pass in a success callback in the validate method to perform your action. The done method, in this case, is redundant.

function validateFormAdd(formName) {
    $("#"+formName).validate({
        rules: {
             ...
        }.
        success: function(label) {
             showToastr('Created', 'Tag Created Successfully!', 'success');
        }
    });
}

Documentation: https://jqueryvalidation.org/validate/#success

nuna's avatar
Level 1
function validateFormAdd(formName) {
    $("#"+formName).validate({
      rules: {
        name: {
            required: true,
            maxlength: 100,
        },
        store_id: {
            required: true,
        },
        code: {
            required: true,
            maxlength: 100,
        },
        description: {
            maxlength: 255,
        },

        success: function(label) {
             showToastr('Created', 'Tag Created Successfully!', 'success');
        }else{
showToastr('Unsuccessful', 'Tag could not be Created!', 'info');
}


      },
    });
  }

Hi, I tried this method.but its not showing anyhing..

bobbybouwmann's avatar

You can do an else on a function... This should give you an error

Let's first get the success message working ;) Delete the else and everything that is in that block. Does it run then? Do you see any errors in your developers' console in the browser?

Please or to participate in this conversation.