surveyjs / custom-widgets

The collection of custom widgets for SurveyJS: Survey Library and Survey Creator :package:
https://surveyjs.io
MIT License
79 stars 78 forks source link

Select2 widget initialization in functional component #247

Closed VerdonTrigance closed 3 years ago

VerdonTrigance commented 3 years ago

Hi there. I found unexpected problems with widget initialization in functional components: https://codesandbox.io/s/reverent-christian-13hzr?file=/src/SurveyComponent.jsx

How to init select2 widget properly with such approach? Looks like all scripts in place, because I can type: $("#sq_100i").select2() in a console and this would work as expected. But select2 not applied automatically in Survey.Survey component. What I'm doing wrong?

PS: I also facing with such error: image I found this part in file \node_modules\select2\dist\js\select2.js, but it shouldn't loads that way. It should be like:

function (root, jQuery) {
      if (jQuery === undefined) {
        // require('jQuery') returns a factory that requires window to
        // build a jQuery instance, we normalize how we use modules
        // that require this pattern but the window provided is a noop
        // if it's defined (how jquery works)
        if (typeof window !== 'undefined') {
          jQuery = require('jquery');
        }
        else {
          jQuery = require('jquery')(root);
        }
      }
      factory(jQuery);
      return jQuery;
    };
tsv2013 commented 3 years ago

Here is the fixed sample - https://codesandbox.io/s/lucid-wozniak-weem6

VerdonTrigance commented 3 years ago

Here is the fixed sample - https://codesandbox.io/s/lucid-wozniak-weem6

Are you sure it works? image You probably changed something and press Ctrl+S. This results to updating 'select' properly. But refresh page in right tab again. This not working.

tsv2013 commented 3 years ago

This results to updating 'select' properly.

Sorry, but I don't understand you. Could you spoecify the exact steps to reproduce the issue, the expected and actual result?

tsv2013 commented 3 years ago

Your screenshot looks ok for me.

VerdonTrigance commented 3 years ago

Your screenshot looks ok for me.

image

Here is no active select2 dropdown as you can see, just ordinary surveyjs dropdown.

tsv2013 commented 3 years ago

One line wasn't saved - https://codesandbox.io/s/lucid-wozniak-weem6?file=/src/SurveyComponent.jsx

image

VerdonTrigance commented 3 years ago

One line wasn't saved - https://codesandbox.io/s/lucid-wozniak-weem6?file=/src/SurveyComponent.jsx

image

Now it works... in sandbox. My project still return TypeError from "PS" part. But I guess it's another topic. Thanks for helping out.