PDA

View Full Version : [Help] How to show/hide combobox trigger dynamically



jomark
2 Dec 2011, 7:13 PM
I have this code below and I want to change the style of a combobox during edit mode and view mode.
I have successfully change the style during view mode but I cant get it back to its original style during edit mode. The trigger button is not shown any more.

Here is my code:

public void onModuleLoad() {
form = new FormPanel();
name = new TextField<String>();
name.setFieldLabel("Please enter name");

btnViewMode = new Button("Set to View Mode");
btnViewMode.addClickHandler(this);

btnEditMode = new Button("Edit Mode");
btnEditMode.addClickHandler(this);

combo = new SimpleComboBox<String>();
combo.setTriggerAction(TriggerAction.ALL);

combo.setFieldLabel("Options");
combo.add("General Administration");
combo.add("Information Technology");
combo.add("Marketing");
combo.add("Accounts");


form.setLabelWidth(150);
form.add(name);
form.add(combo);
form.add(btnViewMode);
form.add(btnEditMode);

RootPanel.get().add(form);
}

@Override
public void onClick(ClickEvent event) {
if(event.getSource().equals(btnViewMode)){
name.el().firstChild().addStyleName("text");
name.setValue("view mode");

combo.el().firstChild().addStyleName("text");
combo.setSimpleValue("view mode");

combo.getElement().setClassName("text");
//combo.el().dom.removeClassName("x-form-trigger-arrow");
}
else{
name.el().firstChild().removeStyleName("text");
name.setValue("edit mode");

combo.el().firstChild().removeStyleName("text");
combo.setSimpleValue("edit mode");

//combo.addStyleName("x-form-trigger x-form-trigger-arrow");
combo.getElement().removeClassName("text");
combo.getElement().setClassName("x-form-trigger");
combo.getElement().setClassName("x-form-trigger-arrow");
}
}