PDA

View Full Version : Disable Checkboxes in CheckBoxListView



imsm
28 Oct 2009, 5:54 AM
Hey,

i try to use the CheckBoxListView to show some uneditable information. This works fine but in this view i don't want the user to be able to select any of the checkboxes. Does anybody know how to implement this?

i tried CheckBoxListVie.disable(). This makes the component grey but i can still select the check boxes.

i tried getSelectionModel().setLocked( true ) but i can still select the check boxes.

Thanxs in advance
Lars

sven
28 Oct 2009, 6:30 AM
Add a click listener to the listview. If the target is the checkbox that is not allowed to be checked, prevent the default action.

ddanny
7 Sep 2010, 3:10 AM
I also have to deal with this issue.
I set the CheckBoxListView disabled (checkBoxListView.setEnabled(false)), it gets grayed out, which is fine, but once I clicked by mistake and was happy to see that the checkbox actually got clicked.
My personal opinion is that setting a widget disabled should not allow the user do operations that change the state of that widget. At least this is how it is on other UI platforms: Swing, SWT, Android,...

Anyway, I tried to follow your suggestion and it doesn't work. The OnClick event is not even issued when I click on a disabled checkbox.

Regards,

Dan

sven
7 Sep 2010, 9:33 AM
If you disable it, than there wont be any events.

Two solutions:

disable and mask the CheckBoxListView or dont disable it and lock the selectionmodel and prevent the default action if the target is a checkbox.

ddanny
14 Sep 2010, 5:34 AM
I tried the second approach by doing this:


checkBoxListView.getSelectionModel().setLocked(true);
checkBoxListView.addListener(Events.OnClick, new Listener<BaseEvent>() {
public void handleEvent(BaseEvent e) {
e.setCancelled(true);
}
});


It looks like I still can check and uncheck the checkboxes. Any ideas?

sven
14 Sep 2010, 5:40 AM
view.getSelectionModel().setLocked(true);
view.addListener(Events.OnClick, new Listener<ListViewEvent<BeanModel>>() {
public void handleEvent(ListViewEvent<BeanModel> e) {
if (e.getTarget().getTagName().equalsIgnoreCase("input")) {
e.preventDefault();
}
}
});

I run this against GXT 2.2 and it was working fine.

canceling an event does not prevent the default action.

ddanny
15 Sep 2010, 3:36 AM
Sven,

How could I implement the "disable and mask the CheckBoxListView". I know how to disable, but not sure how to mask it.

Thanks,

Dan

sven
15 Sep 2010, 3:37 AM
view.mask("Disabled");

ddanny
15 Sep 2010, 3:47 AM
view.setEnabled(false);
view.mask("Disabled");


I see the "Disabled" message before the view is populated, the view looks disabled, but I still can click in it and checkboxes change state.

sven
15 Sep 2010, 3:50 AM
Due to the way ListView works, you can first mask it after loading the data/the view showing the data.

ddanny
15 Sep 2010, 3:58 AM
The listener + locked approach works fine, but the view has an enabled look. That means the user is "invited" to click there.

It looks like the final solution was to use the listener + locked and apply the mask after the view (well, the store) is populated with data.

Thanks,

Dan

sven
15 Sep 2010, 3:58 AM
In the endthe code looks like this:
view.addListener(Events.Refresh, new Listener<ListViewEvent<BeanModel>>() {
public void handleEvent(ListViewEvent<BeanModel> e) {
view.mask("disabled");
}
});
view.disable();

I tested it and it works for me

When the view is masked, you dont need to look at as all events get captured by the mask

ddanny
15 Sep 2010, 4:00 AM
Something similar works, indeed.

Thanks,

Dan

nolio
2 Nov 2010, 9:22 AM
Is there a way to also disabled the entire list (make it look grey-out)? when I try to disable the listView, then the user is able to actually select/unselect the check-boxes in the list

sven
2 Nov 2010, 9:25 AM
I added a change to CheckBoxListView that will prevent clicking the checkboxes when the view is disabled. This change is already in SVN.

nolio
3 Nov 2010, 5:32 AM
Can you elaborate what is the change you have made? I do not wish to checkout the code from trunk, so I will do the modification myself.

sven
3 Nov 2010, 5:34 AM
The change will also be part of GXT 2.2.1. The change i did is explained in this thread. I prevent the default action of the click event, see post #6

meliniak
27 Jan 2011, 12:58 AM
I will stick to this thread as I have a similar question. How would you disable single checkbox, or single entry, depending on the values of properties of the ModelData instances? Any ideas?

meliniak
27 Jan 2011, 4:17 AM
In case anyone is interested, here is the way I did this. I simply overrided refresh method:



@Override
public void refresh() {
super.refresh();

if (rendered) {
NodeList<Element> nodes = el().select(this.getCheckBoxSelector());
for (int i = 0; i < nodes.getLength(); i++) {
Element e = nodes.getItem(i);
if (InputElement.is(e)) {
InputElement ie = InputElement.as(e);

ModelData md = store.getAt(i);
if(YOUR_CONDITION) {
ie.setDisabled(true);
}
}
}
}