2

Is it possible to add a hook method on the client side with a remote validation? I want to check if an email is already taken and if that is true i want to add a button on my form that will show the user with that email address.

note I also check if email is required and or a valid e-mail. the button should only show when an email is already in de database.

(the validation itself works, I just want to catch the event and add a button to my view)

here is my code in the model

  <Remote("ValidateEmail", "User", additionalfields:="UserGuid,PersonGuid", ErrorMessageResourceType:=GetType(Resources.Messages), ErrorMessageResourceName:="UserErrorDuplicateEmail")>
    Public Property Email As String

my javascript

function createValidationCheck() {
$("form input").change(function () {
    console.log("change")
    $("form").valid();
});


$("form").validate({
    invalidHandler: function (event, validator) {
        console.log("TESTING")
    }
})}

this is part of my view

@Using (Ajax.BeginForm("SaveUserDetail", New AjaxOptions With {.HttpMethod = "Post",
                                                                .UpdateTargetId = "displayContainer",
                                                                .OnFailure = "PostFailure",
                                                                .OnSuccess = "fillDisplayContainer",
                                                               .OnComplete = "userDetailFinished"
                                                              }))


         @<div id="detailInformation">
            <h2>@Resources.Labels.UserDetails</h2>

              @Html.HiddenFor(Function(m) m.UserGuid)
               @Html.HiddenFor(Function(m) m.PersonGuid)

              <div class="label">
                @Html.LabelFor(Function(m) m.Email)

            </div>
            <div class="displayForCorrector">
                @Html.TextBoxFor(Function(m) m.Email)
                 @Html.ValidationMessageFor(Function(m) m.Email,Nothing,New With{.id ="ShowEmailList"})
            </div>

In short,How can I catch the validation event and add behaviour to it via jquery?

1
  • I found the solution Just add the following line $("form").bind('invalid-form.validate',addValidationInvalidHandler) Commented Mar 29, 2013 at 9:38

1 Answer 1

3

I found the solution

To add an event just add this in your Javascript

 $("form").bind('invalid-form.validate',addValidationInvalidHandler)

the addValidationInvalidHandler is my own javascript function that get's called everytime my form isn't valid

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

1 Comment

Great... this helped me. If you just check $('form').valid() it is valid but remote validation fails... this hook did it and allowed me to reset a loading spinner icon.

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.