jquery validation problem

Asked

Viewed 114 times

1

I’m using a form to dynamically fill out list items. I clear form fields when entering list items in the item addition act.

Problem:

When I perform Ubmit to record, Razor’s help @Html.ValidationMessageFor intervenes not allowing Submit, because it is necessary to save the items from the parent object list.

Solution to be found:

When performing form Submit. Arrow the form field with required false.

I was kind of trying to manipulate the library $("#form").validate();

I was researching this function, but I still managed to get it to work.

Code:

$(".btnGravarEmpenho").on("click", function () {
    $("#formConvenio").submit();
});

//estava testando essa função
$("#formConvenio").validate({
    rules: {
        input: {
            required: false
        }
    },
    messages: {
        input: {
            required: "fsfafafa"
        }
    },
    ignore: "",
    errorClass: 'fieldError',
    onkeyup: false,
    onblur: false,
    errorElement: 'label',
    submitHandler: function () {
        alert("alert");
    }
});

Of course, the properties that have validation annotations will reflect on the views and controller. But I still need validation when inserting the item, but not Submit. Because what counts is the object list.

  • You can post a sample of the code?

  • How about not calling form Submit and doing the data post manually with $.post();?

  • It can be a Iurístona solution. Avoid finishing the form Ubmit. Or even ajax would also be the solution to send the information to the server.

  • The code comes to fall on Controller? If yes, you can read the value of ModelState?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.