2011-11-05 16:46:53 +00:00
|
|
|
'use strict';
|
|
|
|
|
2011-05-16 10:49:48 +00:00
|
|
|
/*@
|
|
|
|
Ox.FormItem <f:Ox.Element> FormItem Element, wrap form element with an error message
|
2012-05-22 13:14:40 +00:00
|
|
|
([options[, self]]) -> <f> FormItem Element
|
2011-05-16 10:49:48 +00:00
|
|
|
options <o> Options object
|
|
|
|
element <o|null> element
|
|
|
|
error <s> error message
|
|
|
|
self <o> Shared private variable
|
|
|
|
@*/
|
|
|
|
|
2011-04-22 22:03:10 +00:00
|
|
|
Ox.FormItem = function(options, self) {
|
|
|
|
|
2011-06-19 17:48:32 +00:00
|
|
|
self = self || {};
|
|
|
|
var that = Ox.Element({}, self)
|
2011-04-22 22:03:10 +00:00
|
|
|
.defaults({
|
|
|
|
element: null,
|
2012-05-26 15:48:19 +00:00
|
|
|
error: ''
|
2011-04-22 22:03:10 +00:00
|
|
|
})
|
|
|
|
.options(options || {})
|
2011-11-30 14:44:35 +00:00
|
|
|
.addClass('OxFormItem');
|
|
|
|
|
|
|
|
self.description = self.options.element.options('description');
|
|
|
|
if (self.description) {
|
|
|
|
$('<div>')
|
|
|
|
.addClass('OxFormDescription')
|
|
|
|
.html(self.description)
|
|
|
|
.appendTo(that);
|
|
|
|
}
|
|
|
|
that.append(self.options.element);
|
2011-06-19 17:48:32 +00:00
|
|
|
self.$message = Ox.Element()
|
2011-04-22 22:03:10 +00:00
|
|
|
.addClass('OxFormMessage')
|
|
|
|
.appendTo(that);
|
|
|
|
|
2011-05-16 10:49:48 +00:00
|
|
|
/*@
|
|
|
|
setMessage <f> set message
|
|
|
|
(message) -> <u> set message
|
|
|
|
@*/
|
2011-04-22 22:03:10 +00:00
|
|
|
that.setMessage = function(message) {
|
|
|
|
self.$message.html(message)[message !== '' ? 'show' : 'hide']();
|
2011-06-19 17:48:32 +00:00
|
|
|
};
|
2011-04-22 22:03:10 +00:00
|
|
|
|
2011-05-16 10:49:48 +00:00
|
|
|
/*@
|
|
|
|
value <f> get value
|
|
|
|
() -> <s> get value of wrapped element
|
|
|
|
@*/
|
2011-04-22 22:03:10 +00:00
|
|
|
that.value = function() {
|
|
|
|
return self.options.element.value();
|
|
|
|
};
|
|
|
|
|
|
|
|
return that;
|
|
|
|
|
2011-06-19 17:48:32 +00:00
|
|
|
};
|