Subitems in combo box
Is it possible to add subitems to a combo box, similar to the idea of optgroups in a select widget?
Wyatt
May 6,
.aw-optgroup-item {font-style: italic;
font-weight:bold;
background-color:#C3DAF9!important;
color:black!important
}
.aw-alternate-even {background: #ecf5ff;}
.aw-alternate-odd {background: #ffffff}
.aw-control-activated {border:1px SOLID gray!important}
AW.UI.ToolbarCombo = AW.UI.Combo.subclass();
AW.UI.ToolbarCombo.prototype.updateControl = function(minWidth,minListWidth,maxHeight)
{
this.onControlActivated = function(event){
this.getContent('box').setClass('control', 'activated');
}
this.onControlDeactivated = function(event){
this.hidePopup();
this.getContent('box').setClass('control', '');
}
this.maxHeight = maxHeight;
this.minListWidth = minListWidth;
this.minWidth = minWidth;
this.itemHeight = 16;
this.sepHeight = 4;
this.setStyle('border-style','none');
if (AW.ie) this.setStyle('margin-top','-1px');
this.setSize(this.minWidth, this.itemHeight+this.sepHeight);
this.getPopupTemplate().setSize(this.minListWidth,Math.min(this.maxHeight,this.getItemCount()*this.itemHeight+this.sepHeight));
this.getPopupTemplate().setClass('list','control');
this.setOptgroups = function(optgroups)
{
this.optgroups = optgroups;
for(var opts=0;opts < this.optgroups.length;opts++)
{
this.getItemTemplate(this.optgroups[opts]).setClass('optgroup','item');
}
}
this.getItemTemplate().setClass("alternate",
function(){
var optgroups = this.$owner.optgroups;
var altCount = 0,ref=0;
if (optgroups)
for(var opts=0;opts < optgroups.length;opts++)
{
if (optgroups[opts] < this.getViewProperty("position"))
{
if (ref != optgroups[opts])
{
ref = optgroups[opts];
altCount = 0;
};
altCount ++;
}
}
return (this.getViewProperty("position")-ref+altCount) % 2 ? "odd" : "even";
}
);
this.getContent('box/text').setAttribute('readonly', true);
this.getContent('box/text').setStyle('-moz-user-select', 'none');
this.getContent('box/text').setAttribute('onselectstart','return false');
this.onItemClicked = function(event,index)
{
for(var i = 0; i< this.optgroups.length;i++)
{
if (this.optgroups[i] == index)
{
AW.setReturnValue(event, false);
return 1;
}
}
}
}
var fluna_values = [ '','',12,1,2,
'',3,4,5,
'',6,7,8,
'',9,10,11];
var fluna_text = [ '-month-', 'Winter', 'december','january','february',
'Spring', 'march','april','may',
'Summer', 'june','july','august',
'Autumn', 'september','october','november'];
var fluna = new AW.UI.ToolbarCombo;
fluna.setId('fluna');
fluna.setItemText(fluna_text);
fluna.setItemValue(fluna_values);
fluna.setControlText(fluna_text[0]);
fluna.setControlValue(fluna_values[0]);
fluna.setItemCount(fluna_values.length);
fluna.updateControl(80,78,100);//width, width,height
fluna.setOptgroups([1,5,9,13]);// set the optgroups indexes
This topic is archived.
ActiveWidgets is a javascript library for creating user interfaces. It offers excellent performance for complex screens while staying simple, compact and easy to learn. Deployed by thousands of commercial customers in more than 70 countries worldwide.
Copyright © ActiveWidgets 2021