Forked from driehle/backbone-validation-bootstrap.js.coffee
Created
April 3, 2013 11:49
-
-
Save nissoh/5300526 to your computer and use it in GitHub Desktop.
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
_.extend Backbone.Validation.callbacks, | |
valid: (view, attr, selector) -> | |
control = view.$('[' + selector + '=' + attr + ']') | |
group = control.parents(".control-group") | |
group.removeClass("error") | |
if control.data("error-style") == "tooltip" | |
# CAUTION: calling tooltip("hide") on an uninitialized tooltip | |
# causes bootstraps tooltips to crash somehow... | |
control.tooltip "hide" if control.data("tooltip") | |
else if control.data("error-style") == "inline" | |
group.find(".help-inline.error-message").remove() | |
else | |
group.find(".help-block.error-message").remove() | |
invalid: (view, attr, error, selector) -> | |
control = view.$('[' + selector + '=' + attr + ']') | |
group = control.parents(".control-group") | |
group.addClass("error") | |
if control.data("error-style") == "tooltip" | |
position = control.data("tooltip-position") || "right" | |
control.tooltip | |
placement: position | |
trigger: "manual" | |
title: error | |
control.tooltip "show" | |
else if control.data("error-style") == "inline" | |
if group.find(".help-inline").length == 0 | |
group.find(".controls").append("<span class=\"help-inline error-message\"></span>") | |
target = group.find(".help-inline") | |
target.text(error) | |
else | |
if group.find(".help-block").length == 0 | |
group.find(".controls").append("<p class=\"help-block error-message\"></p>") | |
target = group.find(".help-block") | |
target.text(error) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment