forked from 0x2620/oxjs
fix some Select/MenuButton bugs
This commit is contained in:
parent
96b206de1a
commit
cf567e5608
2 changed files with 31 additions and 23 deletions
|
|
@ -17,6 +17,7 @@ Ox.Select <f:Ox.Element> Select Object
|
||||||
maxWidth <n|0> Maximum menu width
|
maxWidth <n|0> Maximum menu width
|
||||||
min <n|1> Minimum number of selected items
|
min <n|1> Minimum number of selected items
|
||||||
overlap <s|'none'> Can be 'none', 'left' or 'right'
|
overlap <s|'none'> Can be 'none', 'left' or 'right'
|
||||||
|
selectable <b|true> is selectable
|
||||||
size <s|'medium'> Size, can be small, medium, large
|
size <s|'medium'> Size, can be small, medium, large
|
||||||
style <s|'rounded'> Style ('rounded' or 'square')
|
style <s|'rounded'> Style ('rounded' or 'square')
|
||||||
title <s|''> Select title
|
title <s|''> Select title
|
||||||
|
|
@ -47,6 +48,7 @@ Ox.Select = function(options, self) {
|
||||||
maxWidth: 0,
|
maxWidth: 0,
|
||||||
min: 1,
|
min: 1,
|
||||||
overlap: 'none', // can be none, left or right
|
overlap: 'none', // can be none, left or right
|
||||||
|
selectable: true,
|
||||||
size: 'medium',
|
size: 'medium',
|
||||||
style: 'rounded',
|
style: 'rounded',
|
||||||
title: '',
|
title: '',
|
||||||
|
|
@ -69,13 +71,14 @@ Ox.Select = function(options, self) {
|
||||||
width: self.options.width - 2 + 'px'
|
width: self.options.width - 2 + 'px'
|
||||||
})
|
})
|
||||||
.bindEvent({
|
.bindEvent({
|
||||||
click: showMenu,
|
anyclick: showMenu,
|
||||||
key_escape: loseFocus,
|
key_escape: loseFocus,
|
||||||
key_down: showMenu
|
key_down: showMenu
|
||||||
});
|
});
|
||||||
|
|
||||||
Ox.Log('Form', 'Ox.Select', self.options);
|
Ox.Log('Form', 'Ox.Select', self.options);
|
||||||
|
|
||||||
|
if (self.options.selectable) {
|
||||||
self.optionGroup = new Ox.OptionGroup(
|
self.optionGroup = new Ox.OptionGroup(
|
||||||
self.options.items,
|
self.options.items,
|
||||||
self.options.min,
|
self.options.min,
|
||||||
|
|
@ -83,6 +86,7 @@ Ox.Select = function(options, self) {
|
||||||
);
|
);
|
||||||
self.options.items = self.optionGroup.init();
|
self.options.items = self.optionGroup.init();
|
||||||
self.checked = self.optionGroup.checked();
|
self.checked = self.optionGroup.checked();
|
||||||
|
}
|
||||||
|
|
||||||
if (self.options.label) {
|
if (self.options.label) {
|
||||||
self.$label = Ox.Label({
|
self.$label = Ox.Label({
|
||||||
|
|
@ -123,12 +127,12 @@ Ox.Select = function(options, self) {
|
||||||
self.$menu = Ox.Menu({
|
self.$menu = Ox.Menu({
|
||||||
element: self.$title || self.$button,
|
element: self.$title || self.$button,
|
||||||
id: self.options.id + 'Menu',
|
id: self.options.id + 'Menu',
|
||||||
items: [{
|
items: [self.options.selectable ? {
|
||||||
group: self.options.id + 'Group',
|
group: self.options.id + 'Group',
|
||||||
items: self.options.items,
|
items: self.options.items,
|
||||||
max: self.options.max,
|
max: self.options.max,
|
||||||
min: self.options.min
|
min: self.options.min
|
||||||
}],
|
} : self.options.items],
|
||||||
maxWidth: self.options.maxWidth,
|
maxWidth: self.options.maxWidth,
|
||||||
side: 'bottom', // FIXME: should be edge
|
side: 'bottom', // FIXME: should be edge
|
||||||
size: self.options.size
|
size: self.options.size
|
||||||
|
|
@ -147,6 +151,7 @@ Ox.Select = function(options, self) {
|
||||||
|
|
||||||
function changeMenu(data) {
|
function changeMenu(data) {
|
||||||
//Ox.Log('Form', 'clickMenu: ', self.options.id, data)
|
//Ox.Log('Form', 'clickMenu: ', self.options.id, data)
|
||||||
|
if (self.options.selectable) {
|
||||||
self.checked = self.optionGroup.checked();
|
self.checked = self.optionGroup.checked();
|
||||||
self.options.value = data.checked.length ? data.checked[0].id : '';
|
self.options.value = data.checked.length ? data.checked[0].id : '';
|
||||||
self.$title && self.$title.html(
|
self.$title && self.$title.html(
|
||||||
|
|
@ -156,6 +161,9 @@ Ox.Select = function(options, self) {
|
||||||
selected: data.checked,
|
selected: data.checked,
|
||||||
value: self.options.value
|
value: self.options.value
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
that.triggerEvent('click', data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTitleWidth() {
|
function getTitleWidth() {
|
||||||
|
|
@ -224,12 +232,12 @@ Ox.Select = function(options, self) {
|
||||||
() -> <o> returns object of selected items with id, title
|
() -> <o> returns object of selected items with id, title
|
||||||
@*/
|
@*/
|
||||||
that.selected = function() {
|
that.selected = function() {
|
||||||
return self.optionGroup.checked().map(function(v) {
|
return self.options.selectable ? self.optionGroup.checked().map(function(v) {
|
||||||
return {
|
return {
|
||||||
id: self.options.items[v].id,
|
id: self.options.items[v].id,
|
||||||
title: self.options.items[v].title
|
title: self.options.items[v].title
|
||||||
};
|
};
|
||||||
});
|
}) : [];
|
||||||
};
|
};
|
||||||
|
|
||||||
/*@
|
/*@
|
||||||
|
|
|
||||||
|
|
@ -39,13 +39,13 @@ Ox.MenuButton = function(options, self) {
|
||||||
})
|
})
|
||||||
.options(options || {})
|
.options(options || {})
|
||||||
.addClass(
|
.addClass(
|
||||||
'OxMenuButton Ox' + Ox.toTitleCase(self.options.style)
|
'OxSelect Ox' + Ox.toTitleCase(self.options.style)
|
||||||
)
|
)
|
||||||
.css(self.options.width == 'auto' ? {} : {
|
.css(self.options.width == 'auto' ? {} : {
|
||||||
width: self.options.width - 2 + 'px'
|
width: self.options.width - 2 + 'px'
|
||||||
})
|
})
|
||||||
.bindEvent({
|
.bindEvent({
|
||||||
click: showMenu
|
anyclick: showMenu
|
||||||
});
|
});
|
||||||
|
|
||||||
if (self.options.type == 'text') {
|
if (self.options.type == 'text') {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue