Announcement

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

    Double requests when using nested object values in ListGrid with search form

    Using latest SmartClientJS 13 LGPL, I have a ListGrid that uses SC13's new "searchForm" property. We have had quite some debate about this in earlier posts but I would prefer to completely ignore that and say that I have the "searchForm" property working now. But not 100% correct for this particular example.

    I have a ListGrid for products. In it, I have the "searchForm" property set to an instance of SearchForm. The search form contains two fields: a TextItem to enter free text and a ComboBoxItem to select a supplier. I also want to filter by one or more properties (things like diameter, length, application, etc.). I've managed to get this working and it looks like this:

    Click image for larger version

Name:	example.png
Views:	121
Size:	12.2 KB
ID:	272417

    The way I got this to work, is by creating the search form with "Search" and "Supplier" fields and (outside of the form) a MenuButton with items being DynamicForms with CheckBoxItems. Each checkbox has a changed() handler that submits the search form. If I do that, of course it doesn't include the properties so I thought to be smart and extend the search form's getValues() method and combine the properties with those values. That method looks like this:
    Code:
    // inside SearchForm
    getValues: function () {
      // propertiesMenuButton.getValues() is custom made and returns something like { diameter: [19, 76] }.
      return isc.addProperties({ properties: propertiesMenuButton.getValues() }, this.Super('getValues');
    }
    The result of a call to searchForm's getValues() then becomes:
    Code:
    {
      properties: { diameter: [19, 76] },
      search: null,
      supplier_id: null
    }
    This more or less works, but I doubt if this is the correct way, because it triggers 2 equal requests. I found out that this happens because "properties" is an object. If I leave that out or pass it a value like null, it won't happen.

    Is this intentional behavior? I need a way to avoid that extra request. Can I somehow integrate the properties inside the search form (not sure which component I would need).

    Hope this is understandable.

    P.S. I could have skipped the whole MenuButton explanation but I wanted to give some context about what problem I'm trying to fix.

    #2
    getValues() isn't something we would consider a valid override point for this kind of thing, because, in order to override it in this way, you would need documentation explaining the sequence of calls, expectations, etc, for an override, and in the absence of that, you are basically just hoping that whatever undocumented behavior you observe is just going to happen to stay that way.

    It's also not necessary in this case, because you have multiple other avenues:

    1) override listGrid.filterEditorSubmit() - as the listGrid.searchForm docs explain, this is how the grid.searchForm feature operates, and is the correct way to add criteria from any other forms to the grid

    .. or ..

    2) just add the items to the searchForm - you mentioned you've got it in a separate form, but it's not clear why. Note that listGrid.searchForm also supports valuesManagers, so, if the form needs to be split up for layout purposes, that is still possible

    Comment


      #3
      I failed to implement all of the options mentioned above.

      For option 1 (the filterEditorSubmit): I don't use a filter editor, so what method do I need to call in the menu button's form when the "Apply" button is clicked?

      For option 2 (the values manager): I get all kinds of errors and it doesn't work. Do I need to do something like this:
      Code:
      isc.ListGrid.create({
        ...,
        valuesManager: isc.ValuesManager.create({
          dataSource: ...,
          members: [<SearchForm instance>, <DynamicForm instance for other properties>]
        })
      });

      Comment


        #4
        Hi wallytax

        for option 2 Isomorphic means to assign the ValuesManager instance to ListGrid.searchForm.
        Per docs, it takes this as well. I did not try it myself, though.

        Best regards
        Blama

        Comment


          #5
          I'm not sure if I have too much customization, but I've tried that and I get messages like "fields argument contains already-created FormItem".
          Should I set the "members" property of the ValuesManager to the individual forms or should I set the "valuesManager" property of each individual form?

          If I don't set the "members" property of the ValuesManager, the ListGrid gives an error when setting an observer on the search form.
          If I set the "members" property, I get the warning I mentioned on the first line.

          Comment


            #6
            Should I set the "members" property of the ValuesManager to the individual forms or should I set the "valuesManager" property of each individual form?
            That should be equivalent. But I remember struggling with this as well, so if the docs are not clear, perhaps Isomorphic could clarify this.

            Best regards
            Blama

            Comment


              #7
              They are equivalent and can be mixed together as well, if you like.

              As far as the errors, we can't really help when you've only posted pseudo-code and haven't posted the actual error either. We can only say: you should not do what that error message is telling you not to do.

              Comment

              Working...
              X