-1

So I read this post but it is not helping at all, I tried to do the same and is not working.

I have this button:

<button id="btnCancel" type="button" class="cancel" name="btnCancel" value="Cancel" onclick="onCancel()">Cancel</button>

Which cleans my form, and causes validation (which I want to remove)

What am I doing wrong?

EDIT: OnCancel function:

function onCancel()
{
    $('#ddlConfigTypeName').val("")
    $('#ddlThreshold').val("")
    $('#ddlValueTypeName').val("")
    $('#txtbLocation').val("")
    $('#txtbLimit').val("")
    $('#QueueMonitorConfigurationsID').val(-1)
    $("#valSummary").empty();
}
Community
  • 1
  • 1
AAlferez
  • 1,480
  • 1
  • 22
  • 48
  • 3
    Don't you need `type="button"` on that? – DGibbs Jun 12 '13 at 15:30
  • TRUE. But I want to hide the validation messages that are shown, so if I click the submit button and there are validation errors, and then I press cancel, I want to erase them – AAlferez Jun 12 '13 at 15:32
  • Have you tried adding it to it? What does 'onCancel()' look like? – DGibbs Jun 12 '13 at 15:39
  • Just added the code. Adding what? – AAlferez Jun 12 '13 at 15:45
  • Yes I did, and is not validating now but still not achieving that – AAlferez Jun 12 '13 at 15:47
  • `not achieving that`, not achieving what? If it is no longer validating, doesn't that answer your question? The problem now lies in the clearing of your form fields validation errors. You will probably want to remove the validation class (.input-validation-error) that the default validation adds via your `onCancel()` method. e.g. `$('#ddlConfigTypeName').removeClass('.input-validation-error');` – DGibbs Jun 12 '13 at 15:51
  • I'm showing the validation messages with a validation summary, not a validation message for each field. And yes the question is answered, I'm just wondering how to do the rest – AAlferez Jun 12 '13 at 15:56
  • If you're using the validation summary then you can toggle this in jquery too `$('div.validation-summary-errors').attr('display', 'none');` or just `$('div.validation-summary-errors').toggle();` – DGibbs Jun 12 '13 at 15:59
  • but then if I click `cancel` again, it will toggle again the errors – AAlferez Jun 12 '13 at 16:02
  • Dont use .toggle() then, use the method before that. Explore a little, this is an easy problem to solve on your own – DGibbs Jun 12 '13 at 16:03
  • Well, it's not working, it does nothing. I debugged and no script errors, and the code is executed, but nothing happens – AAlferez Jun 12 '13 at 16:09

1 Answers1

0

Solved it:

    $('form').find("[data-valmsg-summary=true]")
         .removeClass("validation-summary-errors")
         .addClass("validation-summary-valid")
         .find("ul").empty();

Somehow, only this solution I found HERE worked for me. It's not even the correct answer marked in that post.

Community
  • 1
  • 1
AAlferez
  • 1,480
  • 1
  • 22
  • 48