0

I am trying to display a validation error message beside the form field reportFileURL. Here is the code which submits the form

var uploadForm = $("#uploadMVRContentForm");
        uploadForm.validate({
            submitHandler: function(form) {
                uploadForm.ajaxSubmit({
                    dataType:'json',
                    success:function(result){
                        if(result.success === true ){
                            mvrContentFormDiv.hide();
                            document.getElementById('uploadMVRContentForm').reset();
                            displayMVRContent();
                        }
                        else{
                            alert(result.errorMessage);
                            return false;

                        }

                    }
                });
            },rules: {
                "mediaValueReport.mainTitle": "required",
                "mediaValueReport.reportFileURL": "required",
                "mediaValueReport.indexPageImageURL":"required",
                "mediaValueReport.landingPageImageURL":"required",
                "mediaValueReport.seoURL":"required",
                "reportDate":"required"
            },
            errorElement: "span"
        });

I am using a alertbox to display that the report file is url. Please suggest me a solution for this.

With errorPlacement

 else{
        var error = result.errorMessage;
        errorPlacement: function(error, element) {
        error.insertAfter("#reportFileURL")
        }

        return false;

    }

1 Answer 1

1

you could use the error placement function, like so

errorPlacement: function(error, element) {}

here's a link to the plugin under the options tab explaining how to use it in detail

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for the info, I Added in the else block but its not working... above is the updated code..
the errorPlacement function is for the jQuery plugin, which happens on the client side prior to the ajax post and the else should work as long as result.success == false and result.errorMessage is not empty. if those conditions are met, do you ate least see an alert box?
yes... the alert box is visible if the results.success=false
is it displaying the message?
cool so it's working then. if you need to then display these errors, which could be backend processing errors, you should then pass this to another function to display a modal div popup or a fade in box to show additional errors outside of the form validation; just a suggestion let me know if you further assistance, always glad to help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.