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.3 app/assets/javascripts/kea/extenders/min_length.js
kea-rails-1.0.2 app/assets/javascripts/kea/extenders/min_length.js
kea-rails-1.0.1 app/assets/javascripts/kea/extenders/min_length.js
kea-rails-1.0.0 app/assets/javascripts/kea/extenders/min_length.js