Monday, July 19, 2010

changing the color of the text in the combobox’s Textbox

Haa!! extjs has changed it named to sencha. Well I might be the last one mentioning it :).

Well coming back to what i was about to write in this post. I had this requirement of coloring the text in the combobox's text box. As i searched for it, i could not find a better solution than this one.

The list values in the combobox can be color coded using the template.

combobox.setSimpleTemplate("<font color='{color}'>{name}</font>");

Now if a particular item from the list is selected that has a different color, the color changes to black in the textBox. Inorder to maintain the color of the list item, I tried something like this.

  1: combobox.addSelectionChangedListener(new SelectionChangedListener<ModelData>() {
  2: 	@Override
  3: 	public void selectionChanged(SelectionChangedEvent<ModelData> se) {
  4: 		if(deptjob.getValue() != null ) {
  5:               		ModelData md = combobox.getValue();
  6: 			combobox.el().getChild(0).setStyleAttribute("color", md.get("color").toString());
  7: 		}
  8: 	}
  9: });
Any ideas on a better way in solving this problem is appreciated.

No comments: