Sha256: 7e3238b30462b82b361c03cdcc5f2ae140521f4e7de3a23136a5ae83f2d05caf

Contents?: true

Size: 1015 Bytes

Versions: 24

Compression:

Stored size: 1015 Bytes

Contents

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

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

      var defaults = {
        message: ""
      };

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

        if (validatableValue.indexOf(':') === -1) {
          target.markInvalid(options.message);
          return false;
        }

        hour    = parseInt(validatableValue.split(':')[0], 10);
        minute  = parseInt(validatableValue.split(':')[1], 10);

        if ( (hour < 0 || hour > 23) || (minute < 0 || minute > 59) ) {
          target.markInvalid(options.message);
          return false;
        }

        target.markValid();
        return true;
      };
   
      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/valid_time.js
kea-rails-1.0.2 app/assets/javascripts/kea/extenders/valid_time.js
kea-rails-1.0.1 app/assets/javascripts/kea/extenders/valid_time.js
kea-rails-1.0.0 app/assets/javascripts/kea/extenders/valid_time.js