3d629b78d3fc532f96811a4a030701caf7b4e636
[ccsdk/features.git] /
1 (function( $, app, joey ) {
2
3         var ui = app.ns("ui");
4
5         ui.AbstractField = ui.AbstractWidget.extend({
6
7                 defaults: {
8                         name : "",                      // (required) - name of the field
9                         require: false, // validation requirements (false, true, regexp, function)
10                         value: "",                      // default value
11                         label: ""                               // human readable label of this field
12                 },
13
14                 init: function(parent) {
15                         this._super();
16                         this.el = $.joey(this._main_template());
17                         this.field = this.el.find("[name="+this.config.name+"]");
18                         this.label = this.config.label;
19                         this.require = this.config.require;
20                         this.name = this.config.name;
21                         this.val( this.config.value );
22                         this.attach( parent );
23                 },
24
25                 val: function( val ) {
26                         if(val === undefined) {
27                                 return this.field.val();
28                         } else {
29                                 this.field.val( val );
30                                 return this;
31                         }
32                 },
33
34                 validate: function() {
35                         var val = this.val(), req = this.require;
36                         if( req === false ) {
37                                 return true;
38                         } else if( req === true ) {
39                                 return val.length > 0;
40                         } else if( req.test && $.isFunction(req.test) ) {
41                                 return req.test( val );
42                         } else if( $.isFunction(req) ) {
43                                 return req( val, this );
44                         }
45                 }
46
47         });
48
49 })( this.jQuery, this.app, this.joey );