141
Views
1
Comments
Solved
[Select2] ElementId needs to be a required attribute
Question
Select2
Web icon
Forge asset by Eduardo Luís

Is it possible to make the ElementId a required attribute for the Select2 Widget?  We have teams that were using this widget and left the ElementId blank which causes a Javascript error:

Uncaught ReferenceError: $select is not defined

This appears to be due to this Javascript code being produced:

<script type="text/javascript">
    $(document).ready(function () {
        $select.select2({containerCssClass: ':all:', allowClear: false, minimumResultsForSearch: 0, tags: false, closeOnSelect: true});
        if ($select.hasClass('ThemeGrid_MarginGutter')) {
            var $select2Element = $select.filter('.ThemeGrid_MarginGutter').next('.select2-container');
            if ($select2Element) $select2Element.addClass('ThemeGrid_MarginGutter');
    }});
</script>

The Javascript error is fixed by providing an ElementId in the Select2 widget attributes.  It would be better to have this required such that ServiceStudio could prevent publishing with the error.  Thanks!

UserImage.jpg
Eduardo Luís
Solution

Hello Scott,

yes it's possible to make the ElementId parameter a mandatory one. 

The only reason that it's not it's because you can set it to use a CSS class instead (Class parameter). That allows you to use just one widget to multiple elements.

But if you think that in your particular case the ElementId should be a mandatory parameter then go ahead and set it.


Regards

Eduardo Luís

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.