Announcement

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

    Prevent submit of search form in ListGrid

    Using the latest SmartClientJS 13 LGPL version, I'm trying to prevent a data refresh when a search form is submitted in a ListGrid (thus the "searchForm" property is set to an instance of SearchForm). I have a situation that I want to require certain search fields (conditionally). I have tried asking ChatGPT (free version) for a solution, but that didn't work. Before that I have tried a couple of things myself:
    1. Make the search field required. It doesn't seem to validate the field when submitting the form (which I do programmatically in a changed() event of the search field).
    2. Override the submit() method of the search form and add field errors when a value is missing. This doesn't seem to work either, most likely because the ListGrid observes the submit() method of the "searchForm" property. The observer calls the searchFormChanged() method, but I don't think I should override that, because it is undocumented.
    Is there a way of preventing the submittal or am I misunderstanding the usage of the "searchForm" property?

    #2
    It sounds like what you want is to prevent a search if certain fields have not been filled in in the SearchForm, is that correct?

    What UI are you hoping for here? Do you have a button that the user needs to press in order to search? If so, the event handler there is the natural place to put logic that checks for sufficient criteria in order to search.

    Note that validation on databound SearchForms is reduced, by design: you may have a validator that requires a certain format for a field when saving but that's obviously not correct to apply when the user is trying to enter search criteria. Same with "required" and other validations.

    Comment


      #3
      Yes, that is correct: I have a grid meant for reporting purposes and since the number of records is quite high, I want the user to enter at least a date period to filter by. There's no submit button, the grid reacts on changes in the search form (I have changed() handlers on the fields calling form.submit()).

      For now, I'll proceed with server side validating. I'm not sure if my use case makes enough sense to enable search form validation. I can imagine you've decided to assume all search fields are optional for instance. It obviously isn't in my situation, but I've found a work-around.

      For what it's worth (feel free to comment)... I found a "dirty" client side solution by overriding the search form's getValuesAsAdvancedCriteria() method, perform validations and add field errors if applicable and return the grid's "searchFormCriteria" in case of validation errors. I did this because the code in searchFormChanged() doesn't perform a fetch when the search form's values are equal to the current criteria.

      Comment


        #4
        Oog, yeah that's dirty and we wouldn't recommend it. We recommend the event handler approach described above.

        Note, it may seem like validation is appropriate in this case, but realize that there is really just this one field where you want "required" to actually be enforced, whereas if validation were enabled in general for search criteria entry, it would break in many different ways.

        For example, you are trying to search some field that requires a particular format, you would end up having to enter the search criteria in that format.

        That's clearly wrong, as is enforcing "required" such that you need to fill in search criteria for every field that is "required" to create a new record.

        Indeed, the right validation for search criteria is typically unrelated to validation for saving data. For example, comboBox.minimumSearchLength:

        https://smartclient.com/smartclient-...umSearchLength

        So, the framework is definitely doing the right thing here by ignoring validation when users are entering search criteria. Requiring certain minimum criteria is a distinct use case, which cannot be correctly solved by just turning on validation for search inputs.

        Comment

        Working...
        X