survey-library icon indicating copy to clipboard operation
survey-library copied to clipboard

Inconsistent onChoicesLazyLoad Triggering When Rapidly Changing Search Filter

Open jiyuan12354 opened this issue 8 months ago • 0 comments

Description:

I am experiencing an issue with the onChoicesLazyLoad event in SurveyJS Dropdown. While the event handler is generally functioning as expected, I have noticed a problem when users rapidly and frequently update the search filter. In such cases, the onChoicesLazyLoad event does not always fire consistently, leading to search results that do not reflect the user's most recent input.

Code Example:

survey.onChoicesLazyLoad.add((_, options) => {
  const choicesLazyLoadByUrl = options.question?.choicesLazyLoadByUrl;
  if (choicesLazyLoadByUrl?.url) {
    const url = `${choicesLazyLoadByUrl?.url}?skip=${options.skip}&take=${options.take}&filter=${options.filter}`;
    http.get(url, {}).then(({ data }) => {
      let _options;
      if (choicesLazyLoadByUrl?.path) {
        _options = get(data, choicesLazyLoadByUrl?.path);
      } else {
        _options = data;
      }
      const opts = _options.map((option) => {
        return {
          value: get(option, choicesLazyLoadByUrl.valueName, option.value),
          text: get(option, choicesLazyLoadByUrl.titleName, option.text),
        };
      });
      options.setItems(opts, data.total);
    });
  }
});

Issue Details:

  1. The choicesLazyLoadByUrl is a custom field and functions correctly.
  2. When users rapidly type into the search filter, the onChoicesLazyLoad event is sometimes skipped. This leads to the displayed choices not matching the user's latest input.

Expected Behavior:

The onChoicesLazyLoad event should fire for every change in the search filter, ensuring that the dropdown choices are always based on the latest input string.

Actual Behavior:

When the search filter is updated rapidly, some onChoicesLazyLoad events are not triggered, resulting in outdated search results.

image

Could you please investigate this issue and provide a solution to ensure that the onChoicesLazyLoad event fires correctly even with rapid input changes?

Thank you for your assistance.

jiyuan12354 avatar Jun 17 '24 06:06 jiyuan12354