surveyjs / survey-library

Free JavaScript form builder library with integration for React, Angular, Vue, jQuery, and Knockout.
https://surveyjs.io/form-library
MIT License
4k stars 780 forks source link

Inconsistent onChoicesLazyLoad Triggering When Rapidly Changing Search Filter #8419

Open jiyuan12354 opened 1 week ago

jiyuan12354 commented 1 week ago

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.