jQuery validation is kind of bloated for my purpose, so I found Happy.js. Unfortunately, the validation is only triggered when using a Submit-button, which I don't have. jQuery-validation offered a function "form()" to trigger the validation programmatically, so I tried to implement the function into Happy.js – without any success. I found a happy-callback implementation (commit), but this doesn't work either.
Some code (updated):
$('#someFormSubmit').click(function() {
$('#someForm').submit();
});
$('#someForm').submit(function(event) {
event.preventDefault();
var jqxhr = $.post('/some', $('#someForm').serialize())
.success(function(response) {});
});
$("#someForm").isHappy({
fields: {
'#name': {
required: true,
message: "Hello"
},
},
testMode: true,
unHappy: function () { alert("hello"); },
});
There's no alert from the callbacks and 'happy' is always true, when it should be false.
The form is in a twitter-bootstrap modal box. Due to the separation of modal-body and modal-footer there's only a link .btn to submit, but not a proper input type=submit.
Any solutions?
isHappy
sets up the validation, not runs it. It should be ran when the page is loaded, not on the click event. – Rocket Hazmat$("#someForm").isHappy({
before$('#someForm').submit(function(event) {
. – Rocket Hazmat