Last active
August 29, 2015 14:16
-
-
Save KatsuYuzu/d1af534aed1e64e22247 to your computer and use it in GitHub Desktop.
jQuery.Validation.Unobtrusive handle sample - http://jsfiddle.net/bsq6e1b2/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.input-validation-error { | |
background-color: #ff0000; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form> | |
<div> | |
<input name="hoge" type="text" data-val-required="The field is required." data-val="true" /> | |
<span data-valmsg-for="hoge" data-valmsg-replace="true"></span> | |
</div> | |
<input type="submit" value="save" /> | |
</form> | |
<ul id="console"></ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.validator.unobtrusive.options = { | |
errorPlacement: function ($error, $element) { | |
if ($error.text().length === 0) { | |
$element.triggerHandler("onSuccess"); | |
} else { | |
$element.triggerHandler("onError"); | |
} | |
} | |
}; | |
$("input").on("onSuccess", function () { | |
$("#console").prepend("<li>onSuccess</li>"); | |
}); | |
$("input").on("onError", function () { | |
$("#console").prepend("<li>onError</li>"); | |
}); | |
$(function () { | |
$("form").valid(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: jQuery.Validation.Unobtrusive handle sample | |
authors: | |
- KatsuYuzu | |
resources: | |
- //ajax.aspnetcdn.com/ajax/jquery.validate/1.13.0/jquery.validate.min.js | |
- //ajax.aspnetcdn.com/ajax/mvc/5.2.2/jquery.validate.unobtrusive.min.js | |
wrap: b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
jsfiddle と gist の連携。
ただし、外部リソースの読み込み順を守ってくれない不具合があるみたいで、manifestに書かれた順になるまでリロードが必要。