Min/Max validator

This commit is contained in:
YNH Webdev
2013-09-06 21:47:02 +02:00
parent 133ed9a0be
commit 8b179fd98d
6 changed files with 224 additions and 5 deletions

View File

@@ -1,6 +1,6 @@
// Generated by CoffeeScript 1.6.1
(function() {
var $el, WSF_BUTTON_CONTROL, WSF_CHECKBOX_CONTROL, WSF_CONTROL, WSF_FORM_ELEMENT_CONTROL, WSF_HTML_CONTROL, WSF_INPUT_CONTROL, WSF_REGEXP_VALIDATOR, WSF_TEXTAREA_CONTROL, WSF_VALIDATOR, controls, name, state, trigger_callback, type, typemap, validatormap, _ref, _ref1, _ref2,
var $el, WSF_BUTTON_CONTROL, WSF_CHECKBOX_CONTROL, WSF_CHECKBOX_LIST_CONTROL, WSF_CONTROL, WSF_FORM_ELEMENT_CONTROL, WSF_HTML_CONTROL, WSF_INPUT_CONTROL, WSF_MAX_VALIDATOR, WSF_MIN_VALIDATOR, WSF_REGEXP_VALIDATOR, WSF_TEXTAREA_CONTROL, WSF_VALIDATOR, controls, name, state, trigger_callback, type, typemap, validatormap, _ref, _ref1, _ref2,
__hasProp = {}.hasOwnProperty,
__extends = 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.__super__ = parent.prototype; return child; };
@@ -60,8 +60,46 @@
})(WSF_VALIDATOR);
WSF_MIN_VALIDATOR = (function(_super) {
__extends(WSF_MIN_VALIDATOR, _super);
function WSF_MIN_VALIDATOR() {
return WSF_MIN_VALIDATOR.__super__.constructor.apply(this, arguments);
}
WSF_MIN_VALIDATOR.prototype.validate = function() {
var val;
val = this.parent_control.value();
return val.length >= this.settings.min;
};
return WSF_MIN_VALIDATOR;
})(WSF_VALIDATOR);
WSF_MAX_VALIDATOR = (function(_super) {
__extends(WSF_MAX_VALIDATOR, _super);
function WSF_MAX_VALIDATOR() {
return WSF_MAX_VALIDATOR.__super__.constructor.apply(this, arguments);
}
WSF_MAX_VALIDATOR.prototype.validate = function() {
var val;
val = this.parent_control.value();
return val.length <= this.settings.max;
};
return WSF_MAX_VALIDATOR;
})(WSF_VALIDATOR);
validatormap = {
"WSF_REGEXP_VALIDATOR": WSF_REGEXP_VALIDATOR
"WSF_REGEXP_VALIDATOR": WSF_REGEXP_VALIDATOR,
"WSF_MIN_VALIDATOR": WSF_MIN_VALIDATOR,
"WSF_MAX_VALIDATOR": WSF_MAX_VALIDATOR
};
WSF_CONTROL = (function() {
@@ -271,6 +309,7 @@
WSF_CHECKBOX_CONTROL.prototype.attach_events = function() {
var self;
self = this;
this.checked_value = window.states[this.control_name]['checked_value'];
return this.$el.change(function() {
return self.change();
});
@@ -391,13 +430,56 @@
})(WSF_CONTROL);
WSF_CHECKBOX_LIST_CONTROL = (function(_super) {
__extends(WSF_CHECKBOX_LIST_CONTROL, _super);
function WSF_CHECKBOX_LIST_CONTROL() {
return WSF_CHECKBOX_LIST_CONTROL.__super__.constructor.apply(this, arguments);
}
WSF_CHECKBOX_LIST_CONTROL.prototype.attach_events = function() {
var control, name, self;
self = this;
this.subcontrols = [];
for (name in controls) {
control = controls[name];
if (this.$el.has(control.$el).length > 0) {
this.subcontrols.push(control);
control.on('change', this.change, this);
}
}
};
WSF_CHECKBOX_LIST_CONTROL.prototype.change = function() {
return this.trigger("change");
};
WSF_CHECKBOX_LIST_CONTROL.prototype.value = function() {
var result, subc, _i, _len, _ref;
result = [];
_ref = this.subcontrols;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
subc = _ref[_i];
if (subc.value()) {
result.push(subc.checked_value);
}
}
return result;
};
return WSF_CHECKBOX_LIST_CONTROL;
})(WSF_CONTROL);
typemap = {
"WSF_BUTTON_CONTROL": WSF_BUTTON_CONTROL,
"WSF_INPUT_CONTROL": WSF_INPUT_CONTROL,
"WSF_TEXTAREA_CONTROL": WSF_TEXTAREA_CONTROL,
"WSF_CHECKBOX_CONTROL": WSF_CHECKBOX_CONTROL,
"WSF_FORM_ELEMENT_CONTROL": WSF_FORM_ELEMENT_CONTROL,
"WSF_HTML_CONTROL": WSF_HTML_CONTROL
"WSF_HTML_CONTROL": WSF_HTML_CONTROL,
"WSF_CHECKBOX_LIST_CONTROL": WSF_CHECKBOX_LIST_CONTROL
};
_ref = window.states;