Confirm a selection via button instead of double clicking

When i open a table by clicking the ellipse on a picker field,

image

I can choose any of the items by double-clicking it without any problems. The issue comes when I want to make that same selection by using a confirm button.

image

    if (isValid(person)) {
        closeWithDefaultAction();
        PersonpersonSelected = dataManager.create(Person.class);
        notifications.create().withCaption("Selected").show();
    }

Hello!

Could you clarify do you want to disable selection by double-clicking and use the button to confirm items? Or just want to use additional validation?

I want to use the button to confirm the selection.

the double click to select is not an issue here

Thank you in advance!

You can check items in the LookupAction#setSelectValidator(), for instance:

<pickerField id="orderField" property="order">
    <actions>
        <action id="lookup" type="picker_lookup"/>
        <action id="clear" type="picker_clear"/>
    </actions>
</pickerField>
@Named("orderField.lookup")
private LookupAction<Order> orderFieldLookup;

@Subscribe
public void onInit(InitEvent event) {
    orderFieldLookup.setSelectValidator(context -> {
        Collection<Order> orders = context.getSelectedItems();
        if (orders.size() == 1) {
            Order order = orders.iterator().next();
            return "order 1".equals(order.getNumber());
        }
        return false;
    });
}

You can disable approving items by double-click but still able to select items by clicking them. To achieve this you can do the following in the Lookup Screen:

@Inject
private HBoxLayout lookupActions;
@Inject
private GroupTable<OrderLine> ordersTable;

@Subscribe
public void onAfterShow(AfterShowEvent event) {
    if (lookupActions.isVisible()) {
        // Opened as lookup screen
        ordersTable.setItemClickAction(new BaseAction("lookup_select_stub"));
    }

See demo project: demo.zip (94.2 KB)

1 Like

thankk you so much! ill try it right away!