Announcement

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

    Empty value not always displayed in selectItems with allowEmptyValue

    In our application we use a lot of SelectItems which can contain a lot of data. This is why they are paged, to further limit the result we also include some default filtering, but this should be clearable by the user.

    This however gives some problem when setAllowEmptyValue is set to true. It is a bit inconsistent to determine when the empty value is shown. For example when you first open the selectitem the empty value is shown, but when clearing this default filter the empty value is not shown. For us it would be ideal if the empty value was shown regardless of what the selectitem was filtered on.

    We have a similar problem that the empty value is not shown when you open the selectitem initially, but it is shown when you open it the second time. However at the moment we have not been able to create a testcase for this.

    This was tested with GWT 2.1.0 with SmartGwt Power 3.0 (SmartClient Version: v8.2p_2012-05-02/PowerEdition Deployment (built 2012-05-02)) on Firefox 10

    Code:
    package test.client;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.smartgwt.client.data.DataSource;
    import com.smartgwt.client.types.FetchMode;
    import com.smartgwt.client.widgets.form.DynamicForm;
    import com.smartgwt.client.widgets.form.fields.SelectItem;
    import com.smartgwt.client.widgets.grid.ListGrid;
    import com.smartgwt.client.widgets.grid.ListGridField;
    
    public class AllowEmptyValueTest implements EntryPoint {  
      
        public void onModuleLoad() {  
        	SelectItem item = new SelectItem("test", "test");
       
    		item.setOptionDataSource(DataSource.get("location"));
    		item.setValueField("lctn_pk");
    		item.setDisplayField("lctn_name");;
    		
    		ListGrid listGridProperties = new ListGrid();
    		listGridProperties.setShowFilterEditor(true);
    		listGridProperties.setShowHeader(true);
    		listGridProperties.setCanEdit(false);
    		listGridProperties.setCanResizeFields(true);
    		listGridProperties.setFetchDelay(1000);
    		listGridProperties.setDataFetchMode(FetchMode.PAGED);
    
    		item.setAllowEmptyValue(true);
    		item.setAutoFetchData(false);
    		item.setPickListFields(new ListGridField("lctn_name", "name"));
    		item.setPickListProperties(listGridProperties);
    		
    	
    		DynamicForm form = new DynamicForm();
    		form.setFields(item);
    		form.draw();
        }
    
    }
    Datasource:

    Code:
    <DataSource	ID="location" serverType="sql" tableName="location">
    	<fields>
    		<field primaryKey="true" type="sequence" name="lctn_pk" hidden="true"></field>
    		<field type="text" length="45" name="lctn_name" title="" required="true" canFilter="true" export="true"></field>
    	</fields>
    </DataSource>

    #2
    What is this test case meant to show - the issue with clearing the default value? If so, what actions does the user need to take to reproduce the problem?

    Comment


      #3
      The test case should show that when the user clears the filtering on the selectitem the empty row in the select item is no longer shown. So the user can no longer select an empty value.

      Comment


        #4
        What do you mean by "clears the filtering"? The only apparent way to "clear the filter" in your test case is to select the empty value from the picklist. In this case it is correct that the empty value would no longer be shown in the picklist (since it is already selected).

        Comment


          #5
          I tried to explain it a bit better with screenshots :). At first we are at "EmptyValueShown.PNG". If we clear the filtering on the selectitem (delete the "2") We get to EmptyValueNotShown.PNG.

          I realize that this seems to be a bit of a stupid bug, if the user is clearing or editing criteria on the selectitem, he generally would not want to select an empty value. However we encounter some problems with the empty value not being shown when you initially open the selectitem. But we can not reproduce this very consistently nor create a test case for it.

          And we think that these two issues might be related to each other.

          So can you take a look at the one I described above and let me know if it is clear now?

          Thanks a lot,
          David
          Attached Files
          Last edited by daviddb; 16 May 2012, 01:51.

          Comment


            #6
            For me, the empty value shows up multiple times.
            This happens specifically with cascaded items.
            Set up 2 SelectItems (a and b), both with an empty value of "-Any-" and an allow always.
            set b to be cascaded by a:
            Code:
            SelectItem b = new SelectItem() {
                        @Override
                        protected Criteria getPickListFilterCriteria(){
                        Criteria criteria = new Criteria("NAME", a.getValue());
                        return criteria;
            }
            at first, everything shows up, but then, the user selects a value in a, and b gets filtered. OK so far.

            Then the user goes back selects "-Any-" from a, and b now shows:
            "-Any-"
            "-Any-"
            "...other values..."

            Comment


              #7
              I have exact the same problem. The emptyValue is not consistently rendered, therefore resulting in wrong records being selected.

              I am using the selectItem in a listGrid:
              Code:
              		SelectItem formItem = new SelectItem(field.getName(), field.getTitle()){{
              			setAllowEmptyValue(true);
              			setOptionDataSource(fkDatasource);
              			setValueField(fkDatasource.getPrimaryKeyFieldName());
              			setDisplayField(fkDatasource.getTitleField());
              			setSortField(fkDatasource.getTitleField());		
              			setAutoFetchData(false);
              		}};

              Comment


                #8
                Test case for allowEmptyValues bug

                I've found a way to reproduce this, I wrote a test case for this. Simply open the editor of the second column and scroll up, the empty value is missing. Each record selected now will select the record above it..
                Code:
                public class Test implements EntryPoint {
                	public void onModuleLoad() {
                		HLayout layout = new HLayout();
                		layout.setWidth100();
                		layout.setHeight100();
                		final int testDataCount = 100;
                
                		final DataSource selectItemDS = new DataSource(){{
                			setID("SelectItemDS");
                			DataSourceIntegerField idField = new DataSourceIntegerField("id");
                			idField.setPrimaryKey(true);
                			DataSourceTextField textField = new DataSourceTextField("desc");
                			
                			setFields(new DataSourceField[]{
                				idField,textField	
                			});
                			Record[] testData = new Record[testDataCount];
                			for(int i=0;i<testDataCount;i++){
                				Record record = new Record();
                				record.setAttribute("id", i);
                				record.setAttribute("desc", "Item: " + i);
                				testData[i] = record;
                			}
                
                			setTestData(testData);
                			setClientOnly(true);
                		}};
                		final DataSource listGridDS = new DataSource(){{
                			setID("listGridDS");
                			
                			DataSourceIntegerField idField = new DataSourceIntegerField("id");
                			idField.setPrimaryKey(true);
                			
                			DataSourceIntegerField selectItemField = new DataSourceIntegerField("selectItemField");
                			setFields(idField,selectItemField);
                			
                			
                			setClientOnly(true);
                			Record[] testData = new Record[testDataCount];
                			for(int i=0;i<testDataCount;i++){
                				Record record = new Record();
                				record.setAttribute("id", i);
                				record.setAttribute("selectItemField", i);
                				testData[i]=record;
                			}
                			setTestData(testData);
                		}};
                		
                		ListGrid listGrid = new ListGrid(){{
                			setDataSource(listGridDS);
                			setCanEdit(true);
                			setEditorCustomizer(new ListGridEditorCustomizer() {
                				@Override
                				public FormItem getEditor(ListGridEditorContext context) {
                					if("selectItemField".equals(context.getEditField().getName())){
                						SelectItem tester = new SelectItem("tester"){{
                							setAllowEmptyValue(true);
                							setOptionDataSource(selectItemDS);
                							setSortField("id");
                							setDisplayField("desc");
                							setValueField("id");
                							setAutoFetchData(false);
                						}};
                						return tester;
                					}
                					else{
                						return context.getDefaultProperties();	
                					}
                				}
                			});
                		}};
                		listGrid.fetchData();
                		layout.addMember(listGrid);
                		layout.draw();
                	}
                }
                The key problem is using setAutoFetchData(false);. With setAutoFetchData(true); the behaviour does not exists.
                Last edited by dencel; 25 Jul 2012, 02:18.

                Comment


                  #9
                  For anybody interested I am using the following workaround:

                  don't use setAllowEmptyValues, instead add an icon to the selectItem to clear the current value.

                  Code:
                  SelectItem tester = new SelectItem("tester"){{
                  	setAllowEmptyValue(false);
                  	final PickerIcon clearIcon = new PickerIcon(PickerIcon.CLEAR);
                  	setIcons(clearIcon);
                  	
                  	addIconClickHandler(new IconClickHandler() {
                  		@Override
                  		public void onIconClick(IconClickEvent event) {
                  			event.getItem().setValue((String)null);
                  		}
                  	});
                  	setOptionDataSource(selectItemDS);
                  	setSortField("id");
                  	setDisplayField("desc");
                  	setValueField("id");
                  	setAutoFetchData(false);
                  }};

                  Comment


                    #10
                    Isomorphic,

                    Are you now able to reproduce this bug with the testcase of Dencel?

                    Will this bug be fixed in the near future?

                    Thanks,
                    David

                    Comment


                      #11
                      We have fixed several issues related to missing empty values in PickLists and/or misalignment as a result thereof; the fixes have gone into both SC 8.2p and SC 8.3d codestreams.

                      If there are any remaining issues, please submit a complete reproducing sample such as the one submitted by dencel @ 25th Jul 2012, 11:15 PST (the 8th post), rather than code snippets.
                      Last edited by Isomorphic; 15 Aug 2012, 14:08.

                      Comment

                      Working...
                      X