field-range.min.js 2.53 KB
/*!
 * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014
 * @version 1.3.0
 *
 * Client validation extension for the yii2-field-range extension
 * 
 * Author: Kartik Visweswaran
 * Copyright: 2014, Kartik Visweswaran, Krajee.com
 * For more JQuery plugins visit http://plugins.krajee.com
 * For more Yii related demos visit http://demos.krajee.com
 */!function(r){var t=function(r){return"[object Array]"===Object.prototype.toString.call(r)||"[object Object]"===Object.prototype.toString.call(r)},e=function(t,e){this.$attrTo=r(t),this.$attrFrom=r("#"+e.attrFrom),this.$mainContainer=r("#"+e.container),this.$errorContainer=r("#"+e.errorContainer),this.$errorBlockFrom=this.$attrFrom.closest(".kv-container-from").find(".help-block"),this.$errorBlockTo=this.$attrTo.closest(".kv-container-to").find(".help-block"),this.$errorBlock=this.$errorContainer.find(".help-block"),this.$form=this.$attrFrom.closest("form"),this.errorToMsg="",this.init()};e.prototype={constructor:e,init:function(){var r=this;r.$errorBlockFrom.hide(),r.$errorBlockTo.hide(),r.$form.on("reset.yiiActiveForm",function(){setTimeout(function(){r.reset()},100)}),r.$form.on("afterValidate",function(t,e){var s=r.$attrFrom.attr("id"),o=r.$attrTo.attr("id");s in e&&r.validateAttribute(e[s],s,o),o in e&&r.validateAttribute(e[o],s,o)}),r.$form.on("afterValidateAttribute",function(t,e,s){var o=r.$attrFrom.attr("id"),a=r.$attrTo.attr("id");r.$errorBlock.html(""),r.$errorContainer.removeClass("has-success has-error"),(e.id==o||e.id==a)&&r.validateAttribute(s,o,a)})},validateAttribute:function(e,s,o){var a=this,i=e.length,n="";t(e)&&i?n=1==i?e[0]:e.join("</li><li>"):i>0&&(n=e),""!=n?(a.$errorBlock.html(n),a.$errorContainer.addClass("has-error")):a.$errorContainer.addClass("has-success"),0==e.length?(r("#"+s).closest(".has-error").removeClass("has-error").addClass("has-success"),r("#"+o).closest(".has-error").removeClass("has-error").addClass("has-success")):(r("#"+s).closest(".has-success").removeClass("has-success").addClass("has-error"),r("#"+o).closest(".has-success").removeClass("has-success").addClass("has-error"))},reset:function(){var r=this;r.$errorBlock.html(""),r.$errorContainer.removeClass("has-success has-error"),r.$mainContainer.removeClass("has-success has-error")}},r.fn.kvFieldRange=function(t){var s=Array.apply(null,arguments);return s.shift(),this.each(function(){var o=r(this),a=o.data("kvFieldRange"),i="object"==typeof t&&t;a||o.data("kvFieldRange",a=new e(this,r.extend({},r.fn.kvFieldRange.defaults,i,r(this).data()))),"string"==typeof t&&a[t].apply(a,s)})}}(jQuery);