You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
select2.js can be loaded as AMD-script, it returns Select2 class which can be instantiated.
But language files doesn't support AMD, they expect select2.amd is already injected into jQuery.fn:
BTW the code is not correct - why is this if needed if it fails on the next line (where e is undefined)?
Anyway, let's consider we have an AMD module which loads select2 and a lang file:
define(["jquery", "vendor/select2/select2", "vendor/select2/i18n/ru"],
function ($, Select2) {
var sel = new Select2($(..), { language: "ru"} );
}
It's not guaranteed that select2.js loads before i18n/ru.js because the lang file has no dependency. So we have to define shim in RequireJS's config (for each language!):
@mirari this solution works, but is not right to do that in the source file; for example the node_modules directory in my project is ignored, so other developers will have to do this alternative fix always.
A workaround is to use your solution in the main app file. I've done it and it is working.
@kevin-brown I think this is an important problem. Do we have any news here?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
select2.js can be loaded as AMD-script, it returns
Select2
class which can be instantiated.But language files doesn't support AMD, they expect
select2.amd
is already injected into jQuery.fn:BTW the code is not correct - why is this
if
needed if it fails on the next line (wheree
is undefined)?Anyway, let's consider we have an AMD module which loads select2 and a lang file:
It's not guaranteed that
select2.js
loads beforei18n/ru.js
because the lang file has no dependency. So we have to define shim in RequireJS's config (for each language!):which is tedious.
Language files do not need select2 itself actually. They just need an AMD loader (jQuery.fn.select2.amd), so why not just use UMD pattern?
And why not use i18n plugin from RequireJS?
The text was updated successfully, but these errors were encountered: