1

Forgive me if i open a new question of an old argument, but i can't find any valid solution. I have a form with some field that can become disabled but they must be validated (disabled becasue user is not allowed to fill).

Since the original Javascript Validator excludes submit/reset/image/disabled i decided to modify this file in order to make disabled fields validated.

the code passed from:

.not(":submit, :reset, :image, [disabled]")

to:

.not(":submit, :reset, :image")

but my disabled fields are still ignored. I tried every kind of variations on the theme but i continue to have the issue.

Thanks for any new tip!

1
  • This makes no sense. Disabled controls do not post back so whats the point of validating them on the client. And if you could, and the property was invalid, the form would not submit because of the validation error, but the user cannot correct the error because its disabled, so your app would just freeze! Commented Nov 21, 2014 at 0:17

1 Answer 1

1

I think i found great and elegant solution - just use html attribute readonly and all works just as you expected.

<input type="text" readonly="readonly" />

The problem was that disabled fields are not submitted by forms, and hence probably are not validated. W3C HTML4 Spec

Other solution, found in this question

var val;
$("#clientConfigurationForm").on("change", "input[type=checkbox]", function () {
    val.resetForm();
    $(this)
        .closest("div")
        .find("input, select")
        .not(this)
        .not(":submit")
        .prop("disabled", !$(this).prop("checked"))
        .not(":disabled")  
        .each(function () {
          $(this).valid();
        });
});

val = $("#clientConfigurationForm").validate({

    onkeyup: function (element) {
        $(element).valid();
    },
    focusInvalid: false,
    submitHandler: function (form) {
        alert("submitted");
    }
});
Sign up to request clarification or add additional context in comments.

3 Comments

Nothing to do for me. Tried variation on the theme but it still continues to block validation on disabled fields. It's weird that modifying Jquery.Validate.js directly it blocks disabled fields anyway! :S
When i go deepper i found answer why this is this way. I Updated my answer at the top, hope this will solve your problem.
Yes, it seems the problem is not of validator but the form... I tried the solution with "readonly". For textbox is ok, with select a little bit Tricky and in the end it was not as i wanted (graphically speaking). I used a workaround adding a couple of properties in the model just for validation as a support of the graphical ones. Thanks!

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.