oxjs/source/Ox.UI/js/Form/Ox.FormItem.js
2011-05-16 12:49:48 +02:00

48 lines
1.2 KiB
JavaScript

// vim: et:ts=4:sw=4:sts=4:ft=js
/*@
Ox.FormItem <f:Ox.Element> FormItem Element, wrap form element with an error message
() -> <f> FormItem Element
(options) -> <f> FormItem Element
(options, self) -> <f> FormItem Element
options <o> Options object
element <o|null> element
error <s> error message
self <o> Shared private variable
@*/
Ox.FormItem = function(options, self) {
var self = self || {},
that = new Ox.Element({}, self)
.defaults({
element: null,
error: '',
})
.options(options || {})
.addClass('OxFormItem')
.append(self.options.element);
self.$message = new Ox.Element()
.addClass('OxFormMessage')
.appendTo(that);
/*@
setMessage <f> set message
(message) -> <u> set message
@*/
that.setMessage = function(message) {
self.$message.html(message)[message !== '' ? 'show' : 'hide']();
}
/*@
value <f> get value
() -> <s> get value of wrapped element
@*/
that.value = function() {
return self.options.element.value();
};
return that;
}