validation - My jquery validate method is not being triggered on the form submit -
i prepared admit missing simple here. find documentation on jquery docs page not hold information needed make basic custom validation.
my problem need validate data isn't contained within element i've been using sort of 'dummy' element try , trigger custom method.
<div id="modal-dialog-overlay"> <div id="modal-background"></div> <article id="dialog-form" class="event-module module"> <header> <h6>new event</h6> <section class="module-actions"> <span class="button" onclick="overlay_select('modal-dialog-overlay', true);">cancel</span> <span class="primary button" onclick="createbevent()">create event</span> </section> </header> <section class="wrapper"> @using (html.beginform("createevent", "conversations", formmethod.post, new { enctype = "multipart/form-data", id = "createeventform", @class = "group" })) { <input id="participantschecker" type="text" /> <input class="submit" type="submit" value="submit"/> } </section> </article> </div> </div>
and javascript bits are
$.validator.addmethod("checkparticipants", function (value, element) { alert($(".event-module .contact-handle [name='key']").length); return $(".event-module .contact-handle [name='key']").length }, "you need invite @ least 1 person."); $("#createeventform").validate({ rules: { participantschecker: { checkparticipants: true } } });
which in document.onready page. there's other code on page adds elements that selector looking , there. in case, alert never appears when form submitted. testing hitting submit without entering @ form.
input elements must have name , that's how jquery validate interacts them:
<input id="participantschecker" name="participantschecker" type="text" />
that should work.
Comments
Post a Comment