Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Start editing filter editor as it's drawn

    Hello,

    I have a subclass of SelectItem that uses a custom picklist with a filter editor enabled. I'm trying to focus the cursor on filter editor as soon as it's opened, so the user can click the SelectItem once and start typing. I'm having trouble capturing the point in time where the filter editor is drawn/initialized. I've tried adding DrawHandlers and InitHandlers to various objects, but I kept getting errors saying my picklist wasn't initialized. The code below doesn't throw any errors, but key startEditing() line never gets called.

    I realize this is a roundabout way of searching in a dropdown, but the custom SelectItem class we wrote is (mostly) working the way we'd like, and is used a lot throughout our app. So I'm trying to avoid major changes to it.

    Is there a handler I can add that will fire when the picklist's filter editor is initialized?

    Code:
            
    //In the constructor of my subclass of SelectItem
            final ListGrid pickList = new ListGrid();
            pickList.setShowFilterEditor(true);
    
            ListGridField viewField = new ListGridField("view");
            viewField.setFilterOperator(OperatorId.IREGEXP);
            viewField.setAllowFilterOperators(true);
            pickList.setAllowFilterExpressions(true);
    
           //I've also tried pickList.setInitHandler(); here.
    
            final TextItem searchBox = new TextItem();
            searchBox.setInitHandler(new FormItemInitHandler()
            {      
                @Override
                public void onInit(FormItem item)
                {
                    pickList.getFilterEditor().startEditing();
                }              
            });
            setPickListProperties(pickList);
    Thanks,
    John Claxton

    #2
    Take into account that you are trying to call a method on the pickList variable, which is just a configuration object, not the live pickList.

    Please, try the following code:
    Code:
        public void onModuleLoad() {
            DynamicForm form = new DynamicForm();
    
            final CustomSelectItem customSelectItem = new CustomSelectItem();
            customSelectItem.setName("itemName");
            customSelectItem.setOptionDataSource(ds);
            customSelectItem.setTitle("Name");
            customSelectItem.setWidth(200);
            customSelectItem.setAutoFetchData(false);
    
            form.setFields(customSelectItem);
            form.draw();
        }
    
        public class CustomSelectItem extends SelectItem {
    
            private boolean isFilterEditorVisible = false;
    
            public CustomSelectItem() {
    
                ListGrid pickListProperties = new ListGrid();
                pickListProperties.setShowFilterEditor(true);
    
                ListGridField viewField = new ListGridField("itemName");
                final TextItem searchBox = new TextItem();
                viewField.setFilterEditorProperties(searchBox);
                setPickListFields(viewField);
    
                pickListProperties.addDataArrivedHandler(new com.smartgwt.client.widgets.grid.events.DataArrivedHandler() {
                    @Override
                    public void onDataArrived(com.smartgwt.client.widgets.grid.events.DataArrivedEvent event) {
                        if (!isFilterEditorVisible) {
                            isFilterEditorVisible = true;
                            ListGrid lg = (ListGrid)event.getFiringCanvas();
                            lg.focusInFilterEditor();
                        }
                    }
                });
                pickListProperties.addVisibilityChangedHandler(new VisibilityChangedHandler() {
                    @Override
                    public void onVisibilityChanged(VisibilityChangedEvent event) {
                        // if isVisible is true, and visibility is changing, we are now hidden
                        if (event.getIsVisible()) isFilterEditorVisible = false;
                    }
                });
                setPickListProperties(pickListProperties);
            }
        }
    The logic is designed to only focus in the filterEditor if the pickList has just become visible, because otherwise, you end up moving focus around while the user is typing in filter criteria.

    Regards
    Isomorphic Software

    Comment

    Working...
    X