Announcement

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

    [BUG] SelectItem doesn't keep selected values after filtering

    SmartClient Version: v9.1p_2014-08-05/LGPL Development Only (built 2014-08-05) in Firefox 26 for developement purpose only. Tested compiled against lastest versions

    Configured a selectItem with listGridProperties to enable filtering and sorting and setting multiple is true, if you select a row and then filter and select another row, the previous selection it's replaced with the new one. But then if you clean the filter and select a another row, both selections are kept. Selection is kept only when clearing the filter

    In preovious post you said that is a common issue in client-only dataSources. This happens with normal dataSources too

    TestCase
    Code:
    DynamicForm dynamicForm = new DynamicForm();
    
    // ListGrid para cuando se despliega el selectItem de Pais
    ListGrid paisListGridProperties = new ListGrid();
    paisListGridProperties.setShowFilterEditor(true);
    paisListGridProperties.setCellHeight(25);
    paisListGridProperties.setShowHeader(true);
    ListGridField idField = new ListGridField("id", "Id");
    idField.setHidden(true);
    ListGridField nameField = new ListGridField("name", "Name");
    paisListGridProperties.setFields(idField, nameField );
    paisListGridProperties.setSortField("name");
    
    SelectItem paisesComboBoxItem = new SelectItem("country", "Country");
    paisesComboBoxItem.setTitleOrientation(TitleOrientation.TOP);
    paisesComboBoxItem.setEmptyDisplayValue("Empty");
    paisesComboBoxItem.setOptionDataSource(TestDS.getInstance());
    paisesComboBoxItem.setValueField("id");
    paisesComboBoxItem.setDisplayField("name");
    paisesComboBoxItem.setPickListProperties(paisListGridProperties);
    paisesComboBoxItem.setMultiple(true);
    paisesComboBoxItem.setMultipleAppearance(MultipleAppearance.PICKLIST);
    
    dynamicForm.setItems(paisesComboBoxItem);
    
    dynamicForm.draw();
    TestDS
    Code:
    public static class TestDS extends DataSource {
    
    private static TestDS instance = null;
    
    	public static TestDS getInstance() {
    		if (instance == null) {
    			instance = new TestDS("testDS");
    		}
    
    		return instance;
    	}
    
    	public TestDS(String idDataSource) {
    		super();
    
    		// Establecer Id del DataSource
    		setID(idDataSource);
    		setDataFormat(DSDataFormat.JSON);
    		setDataURL("test.js");
    
    		// ID
    		DataSourceIntegerField id = new DataSourceIntegerField("id", "Id");
    		id.setPrimaryKey(true);
    
    		// Código
    		DataSourceTextField name = new DataSourceTextField("name", "Name");
    
    		// Asignar campos al Data Source
    		setFields(id, name);
    	}
    
    }
    test.js
    Code:
    [
    	{
    		id : 0,
    		name : "Spain"
    	}, 
    	{
    		id : 1,
    		name : "United Kingdom"
    	},
    	{
    		id : 2,
    		name : "USA"
    	},
    	{
    		id : 3,
    		name : "Japan"
    	}
    ]
    Old related post => http://forums.smartclient.com/showth...427#post122427

    Best regards
    Last edited by hespresati; 6 Aug 2014, 02:53. Reason: Fix

    #2
    FilterEditor + multiple selection doesn't make sense together, because it would require the user to actually perform a search to find previously selected records to de-select them.

    Current framework code actually warns you not to use this settings together for this reason.

    For this kind of scenario, use MultiComboBoxItem instead.

    Comment


      #3
      Hi there. First of all thanks for your support...

      In our application the goal of this section is to select multiple locations from a province in a country. Country and Province are dependant SelectItems, and the Locations one (now a MultiComboBoxItem) must be dependant from Province (no method such setPickListCriteriaFunction or fetch to do it manually) as show in attached image. Also, seems that there's no way to access the selected data as records (getValueAsRrecordList throw JSNI type exception recieveing int and expecting JavaScriptObject). Ho we can reach this dependant MultiComboBoxItem and access all the underlaying data as records?

      Best regards
      Attached Files

      Comment


        #4
        You can provide a PickListCriteriaFunction via setComboBoxProperties.

        The value of a MultiComboBoxItem is an Array of primaryKeys. This is the same as a SelectItem with multiple:true. In both cases it would be invalid to call getValueAsRecordList().

        Since the selected records are not actually guaranteed to be loaded from the server, the right approach if you need the complete records is to actually fetch them from the server (using DataSource.fetchData()).

        Comment


          #5
          Thanks for your support and the workaround. Following that way, when we set PickListCriteriaFunction the written value in the comboBox is not passed to the filter by default (unlike selectItems). I've been looking to get it from the comboBoxItem and add it to the returning criteria but I can't find it in the properties. How can I get it?

          Code:
          ComboBoxItem localidadesComboBoxProperties = new ComboBoxItem();
          localidadesComboBoxProperties.setPickListFilterCriteriaFunction(new FormItemCriteriaFunction() {
          	@Override
          	public Criteria getCriteria(FormItemFunctionContext itemContext) {
          		if (provinciasComboBoxItem.getValue() != null)
          			return new Criteria("provincia/idProvincia", provinciasComboBoxItem.getValue().toString());
          		else
          			return null;
          	}
          });
          Best regards and again thanks for your support

          Comment


            #6
            Hi hespresati,

            I'm not perfectly sure if this might be a problem in your case, but if you work with the PickList of a ComboBoxItem, make sure that it has all needed fields in setPickListFields(ListGridField...). Fields you only need to access that should not be displayed can be marked hidden.

            Besides, is "provincia/idProvincia" really working as fieldname (with respect to serverds.DataSourceField.name)?

            Best regards,
            Blama

            Comment


              #7
              Aside from the issue noted by Blama (invalid field name), your code appears to be trying to get a value from another ComboBoxItem, but you haven't shared the code for that.

              Note that, if you are trying to get the value for the MultiComboBoxItem, you should use FormItemFunctionContext.getFormItem().getValue() / getEnteredValue().

              Comment


                #8
                Hi Blama and Isomorphic,

                I'll try to use the pickList in the multiComboBoxItem to access all the needed data instead of using a fetch to the dataSource to avoid possible race conditions. That works...but just for better code

                "provincia/idProvincia" is not a field in a server dataSource. Is a way to point to a related field in our custom back-end implementation. That works in the client dataSource as a field of a related dataSource, too. That code follow the example of dependant selectItems, but applied to a comboBoxItem: get all the localities from a given province selected in the previous selectItem.

                As I said, the problem is that if we define that function, the entered value for filtering is not added to the criteria defined in pickListCriteriaFunction. And I can't access the entered value by the user in the comboBox's textField via itemContext.getFormItem().getValue() which is always null or .getEnteredValue() that is no defined for itemContext's formItem or multiComboBoxItem neither. Only the province id is passed to the criteria and not the filtering name written by the user, always fetching the entire set of localities for that province.

                Thanks for your help

                Comment


                  #9
                  Solved with the hint of getEnteredValue(), which is defined for ComboBoxItem and you have to add a cast to the formItem from the itemContext:

                  Code:
                  ((ComboBoxItem) itemContext.getFormItem()).getEnteredValue());
                  Now I can add the input value to the defined criteria and everything works fine. Thank you so much for your help

                  Best regards

                  Comment

                  Working...
                  X