Sha256: dd342c62816ddaba0940480e687734824efd2360064ed0b3fb7f22ccdb243947

Contents?: true

Size: 991 Bytes

Versions: 24

Compression:

Stored size: 991 Bytes

Contents

(function(ko, $) {
  "use strict";

  ko.extenders.minLength = function(target, options) {
      ko.utils.validatorBase(target);

      var defaults = {
        message: "",
        length: 0,
        allowBlank: false
      };

      options = $.extend({}, defaults, options);
   
      target.validate = function validate(newValue, newComparisonValue) {
        var validatableValue  = typeof newValue === 'undefined' ? target() : newValue;

        if (options.allowBlank && (!validatableValue || validatableValue === '')) {
          target.markValid();
          
          return !target.hasError();
        }

        if (typeof validatableValue !== 'undefined' && validatableValue.length >= options.length) {
          target.markValid();
        } else {
          target.markInvalid(options.message);
        }

        return !target.hasError();
      };
   
      target.subscribe(target.validate);
   
      //return the original observable
      return target;
  };

})(ko, $);

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
kea-rails-1.0.9 app/assets/javascripts/kea/extenders/min_length.js
kea-rails-2.0.0.pre.alpha14 app/assets/javascripts/kea/extenders/min_length.js
kea-rails-2.0.0.pre.alpha13 app/assets/javascripts/kea/extenders/min_length.js
kea-rails-2.0.0.pre.alpha12 app/assets/javascripts/kea/extenders/min_length.js
kea-rails-2.0.0.pre.alpha11 app/assets/javascripts/kea/extenders/min_length.js
kea-rails-2.0.0.pre.alpha10 app/assets/javascripts/kea/extenders/min_length.js
kea-rails-2.0.0.pre.alpha9 app/assets/javascripts/kea/extenders/min_length.js
kea-rails-2.0.0.pre.alpha8 app/assets/javascripts/kea/extenders/min_length.js
kea-rails-2.0.0.pre.alpha7 app/assets/javascripts/kea/extenders/min_length.js
kea-rails-2.0.0.pre.alpha6 app/assets/javascripts/kea/extenders/min_length.js
kea-rails-2.0.0.pre.alpha5 app/assets/javascripts/kea/extenders/min_length.js
kea-rails-2.0.0.pre.alpha4 app/assets/javascripts/kea/extenders/min_length.js
kea-rails-2.0.0.pre.alpha3 app/assets/javascripts/kea/extenders/min_length.js
kea-rails-2.0.0.pre.alpha2 app/assets/javascripts/kea/extenders/min_length.js
kea-rails-1.0.8 app/assets/javascripts/kea/extenders/min_length.js
kea-rails-2.0.0.pre.alpha1 app/assets/javascripts/kea/extenders/min_length.js
kea-rails-1.0.7 app/assets/javascripts/kea/extenders/min_length.js
kea-rails-1.0.6 app/assets/javascripts/kea/extenders/min_length.js
kea-rails-1.0.5 app/assets/javascripts/kea/extenders/min_length.js
kea-rails-1.0.4 app/assets/javascripts/kea/extenders/min_length.js