0

In my .Net core MVC app I am trying to post form from js ($.ajax) Before posting from JS I am trying to validate inputs.

When I do submit from button

<input type="submit" class="btn-primary col-lg-6"  value="Knjiži" />

My form return nicely formatted validation errors. enter image description here

But when I try to validate my form inside JS on event bidden to click buuton like

 <button id="knjiziDugme"  class="btn-primary col-lg-6">Knjiži KO - Povrat</button>


$("#knjiziDugme").on("click", function (event) {

                if ($("#formaKnjizi").valid()) {
                    var url = "../../PovratniceMpo/Knjizi"
                    var formData = $('#formaKnjizi').serialize();
                    $.ajax({
                        url: url,
                        type: "POST",
                        data: formData,
                        dataType: "json",
                        success: function (resp) {
                            console.log(resp);
                        }
                    });
                };
            });

My form be validated but messages are ugly enter image description here

How I can preform validation inside JS as it does form automatically on Submit?

Sparky
  • 98,165
  • 25
  • 199
  • 285
adopilot
  • 4,340
  • 12
  • 65
  • 92
  • Possible duplicate of [Trigger standard HTML5 validation (form) without using submit button?](https://stackoverflow.com/questions/7002230/trigger-standard-html5-validation-form-without-using-submit-button) – DNKROZ Sep 05 '17 at 15:07
  • 1
    Do not use JavaScript/jQuery for validation if you want to use HTML5 validation. – Sparky Sep 05 '17 at 17:24

0 Answers0