2 * Copyright 2010-2013 Ben Birch
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this software except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 (function( $, app, joey ) {
18 var ui = app.ns("ui");
20 ui.AbstractField = ui.AbstractWidget.extend({
23 name : "", // (required) - name of the field
24 require: false, // validation requirements (false, true, regexp, function)
25 value: "", // default value
26 label: "" // human readable label of this field
29 init: function(parent) {
31 this.el = $.joey(this._main_template());
32 this.field = this.el.find("[name="+this.config.name+"]");
33 this.label = this.config.label;
34 this.require = this.config.require;
35 this.name = this.config.name;
36 this.val( this.config.value );
37 this.attach( parent );
40 val: function( val ) {
41 if(val === undefined) {
42 return this.field.val();
44 this.field.val( val );
49 validate: function() {
50 var val = this.val(), req = this.require;
53 } else if( req === true ) {
54 return val.length > 0;
55 } else if( req.test && $.isFunction(req.test) ) {
56 return req.test( val );
57 } else if( $.isFunction(req) ) {
58 return req( val, this );
64 })( this.jQuery, this.app, this.joey );