public function Field($properties = array()) { Requirements::javascript(BOLTTOOLS_DIR . '/javascript/addnewlistboxfield.js'); $this->setTemplate('AddNewListboxField'); $this->addExtraClass('has-chzn'); return parent::Field($properties); }
public function Field($properties = array()) { FormExtraJquery::include_jquery(); // Use updated version of Chosen Requirements::block(FRAMEWORK_ADMIN_DIR . '/thirdparty/chosen/chosen/chosen.css'); Requirements::block(FRAMEWORK_ADMIN_DIR . '/thirdparty/chosen/chosen/chosen.jquery.js'); Requirements::css(FORM_EXTRAS_PATH . '/javascript/chosen/chosen.min.css'); Requirements::javascript(FORM_EXTRAS_PATH . '/javascript/chosen/chosen.jquery.js'); if ($this->use_order) { Requirements::javascript(FORM_EXTRAS_PATH . '/javascript/chosen_order/chosen.order.jquery.js'); } // Init $opts = array('no_results_text' => $this->no_results_text, 'allow_single_deselect' => $this->allow_single_deselect ? true : false); if (self::config()->rtl) { $this->addExtraClass('chosen-rtl'); } if ($this->allow_max_selected) { $opts['allow_max_selected'] = $this->allow_max_selected; } if ($this->use_order) { $stringValue = $this->value; if (is_array($stringValue)) { $stringValue = implode(',', $stringValue); } $this->setAttribute('data-chosen-order', $stringValue); } $this->setAttribute('data-chosen', json_encode($opts)); Requirements::javascript(FORM_EXTRAS_PATH . '/javascript/ChosenField.js'); return parent::Field($properties); }
/** * @param array $parameters * @return string */ public function Field($parameters = array()) { $field = parent::Field($parameters); if ($this->autocomplete) { $this->addExtraClass("chosenAutocompleteField"); $field = parent::Field($parameters); Requirements::css("dropdown2autocomplete/javascript/chosen/chosen.min.css"); Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js'); Requirements::javascript("dropdown2autocomplete/javascript/chosen/chosen.jquery.min.js"); Requirements::customScript(' jQuery("#' . $this->ID() . '").chosen(' . $this->Config()->get("js_settings") . '); jQuery("body").on( "focus", ".chosenAutocompleteField:visible", function(){ jQuery(this).chosen(' . $this->Config()->get("js_settings") . '); } ); ', $this->ID() . "_chosen_setup"); } return $field; }
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); }
public function testFieldRenderingMultipleOn() { $choices = array('a' => 'a value', 'b' => 'b value', 'c' => 'c value'); $field = new ListboxField('Choices', 'Choices', $choices); $field->multiple = true; $field->setValue('a,c'); $parser = new CSSContentParser($field->Field()); $optEls = $parser->getBySelector('option'); $this->assertEquals(3, count($optEls)); $this->assertEquals('selected', (string) $optEls[0]['selected']); $this->assertEquals('', (string) $optEls[1]['selected']); $this->assertEquals('selected', (string) $optEls[2]['selected']); }
/** * @param array $properties * @return HTMLText */ public function Field($properties = array()) { Requirements::css(MULTISELECT_BASE . '/thirdparty/multiselect/css/ui.multiselect.css'); Requirements::css(MULTISELECT_BASE . '/css/MultiSelectField.css'); Requirements::javascript(MULTISELECT_BASE . '/thirdparty/multiselect/js/ui.multiselect.js'); Requirements::javascript(MULTISELECT_BASE . '/javascript/MultiSelectField.js'); return parent::Field($properties); }