oxjs/source/Ox.UI/js/Form/FormItem.js

54 lines
1.3 KiB
JavaScript
Raw Normal View History

2011-11-05 16:46:53 +00:00
'use strict';
2011-05-16 10:49:48 +00:00
/*@
2012-05-31 10:32:54 +00:00
Ox.FormItem <f> FormItem Element, wraps form element with an error message
([options[, self]]) -> <o:Ox.Element> 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) {
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>')
2012-06-14 10:34:46 +00:00
.addClass('OxFormDescription OxSelectable')
2011-11-30 14:44:35 +00:00
.html(self.description)
.appendTo(that);
}
that.append(self.options.element);
self.$message = Ox.Element()
2012-06-14 10:34:46 +00:00
.addClass('OxFormMessage OxSelectable')
2011-04-22 22:03:10 +00:00
.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-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;
};