este-library-oldschool
Version:
Library for github.com/steida/este.git
63 lines (57 loc) • 1.8 kB
JavaScript
// Generated by github.com/steida/coffee2closure 900.1.18
/**
@fileoverview Validate value existence. Returns false for null, undefined,
empty string and empty array. String is trimmed before length check.
*/
var extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.superClass_ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
goog.provide('este.validators.Required');
goog.provide('este.validators.required');
goog.require('este.validators.Base');
goog.require('goog.string');
/**
@param {function(): string=} getMsg
@constructor
@extends {este.validators.Base}
*/
este.validators.Required = function(getMsg) {
este.validators.Required.superClass_.constructor.call(this, getMsg);
}
extend(este.validators.Required, superClass);
/**
@override
*/
este.validators.Required.prototype.isValidable = function() {
return true;
};
/**
@override
*/
este.validators.Required.prototype.validate = function() {
switch (goog.typeOf(this.value)) {
case 'string':
return goog.string.trim(this.value + '').length > 0;
case 'array':
return this.value.length > 0;
default:
return this.value != null;
}
};
/**
@override
*/
este.validators.Required.prototype.getMsg = function() {
/**
@desc Required validator message.
*/
return este.validators.Required.MSG_VALIDATOR_REQUIRED = goog.getMsg('This field is required.');
};
/**
@param {function(): string=} getMsg
@return {function(): este.validators.Required}
*/
este.validators.required = function(getMsg) {
return function() {
return new este.validators.Required(getMsg);
};
};