public function Field($properties = array())
 {
     FormExtraJquery::include_jquery();
     if ($this->requireAccounting) {
         FormExtraJquery::include_accounting();
     }
     FormExtraJquery::include_jquery_ui();
     if (Director::isDev()) {
         Requirements::css(FORM_EXTRAS_PATH . '/javascript/appendgrid/jquery.appendGrid-1.6.0.css');
         Requirements::javascript(FORM_EXTRAS_PATH . '/javascript/appendgrid/jquery.appendGrid-1.6.0.js');
     } else {
         Requirements::css(FORM_EXTRAS_PATH . '/javascript/appendgrid/jquery.appendGrid-1.6.0.min.css');
         Requirements::javascript(FORM_EXTRAS_PATH . '/javascript/appendgrid/jquery.appendGrid-1.6.0.min.js');
     }
     if (!FormExtraJquery::isAdminBackend()) {
         Requirements::customScript('var appendgrid_' . $this->ID() . ' = ' . $this->buildJsonOpts(true));
     } else {
         Requirements::css(FORM_EXTRAS_PATH . '/javascript/appendgrid/silverstripe.css');
     }
     Requirements::javascript(FORM_EXTRAS_PATH . '/javascript/AppendGridField.js');
     return parent::Field($properties);
 }
 public function Field($properties = array())
 {
     FormExtraJquery::include_jquery();
     $use_v3 = self::config()->use_v3;
     if ($use_v3) {
         Requirements::css(FORM_EXTRAS_PATH . '/javascript/select2-v3/select2.css');
         Requirements::javascript(FORM_EXTRAS_PATH . '/javascript/select2-v3/select2.min.js');
         // Locale support
         $lang = i18n::get_lang_from_locale(i18n::get_locale());
         if ($lang != 'en') {
             Requirements::javascript(FORM_EXTRAS_PATH . '/javascript/select2-v3/select2_locale_' . $lang . '.js');
         }
     } else {
         // Locale support
         $lang = i18n::get_lang_from_locale(i18n::get_locale());
         if ($lang != 'en') {
             Requirements::javascript(FORM_EXTRAS_PATH . '/javascript/select2-v4/i18n/' . $lang . '.js');
         }
         // Use full release
         Requirements::css(FORM_EXTRAS_PATH . '/javascript/select2-v4/css/select2.min.css');
         FormExtraJquery::include_mousewheel();
         Requirements::javascript(FORM_EXTRAS_PATH . '/javascript/select2-v4/js/select2.full.min.js');
     }
     // Build options
     $opts = array();
     if ($this->allow_single_deselect) {
         if ($use_v3) {
             $opts['allowClear'] = $this->allow_single_deselect;
         } else {
             $opts['allow_clear'] = $this->allow_single_deselect;
         }
     }
     if ($this->allow_max_selected) {
         if ($use_v3) {
             $opts['maximumSelectionSize'] = $this->allow_max_selected;
         } else {
             $opts['maximumSelectionLength'] = $this->allow_max_selected;
         }
     }
     if ($this->tags) {
         if ($use_v3) {
             if (is_array($this->source)) {
                 $source = array_values($this->source);
             } else {
                 $source = array();
             }
             // Tags is an array
             $opts['tags'] = $source;
             $opts['tokenSeparators'] = $this->token_separators;
             // Not compatible with select
             $this->multiple = false;
             $this->template = 'HiddenField';
         } else {
             // Tags are calculated from options
             $opts['tags'] = $this->tags;
             $opts['token_separators'] = $this->token_separators;
             $opts['free_order'] = $this->free_order;
         }
     }
     if (self::config()->rtl && !$use_v3) {
         $opts['dir'] = 'rtl';
     }
     if ($this->ajax) {
         $opts['ajax'] = $this->ajax;
     }
     if (FormExtraJquery::isAdminBackend()) {
         Requirements::customScript('var select2_' . $this->ID() . ' = ' . json_encode($opts));
         Requirements::javascript(FORM_EXTRAS_PATH . '/javascript/Select2Field.js');
     } else {
         Requirements::customScript('jQuery("#' . $this->ID() . '").select2(' . json_encode($opts) . ');');
     }
     if ($use_v3) {
         // If you need to adjust the size, it's better to use the field container instead
         $this->setAttribute('style', 'width:100%');
     }
     return parent::Field($properties);
 }