Class Selectize

All Implemented Interfaces:
Serializable, Iterable, IEventSink, IEventSource, IFeedbackContributor, IConverterLocator, IGenericComponent, IMetadataContext, IFormModelUpdateListener, IFormVisitorParticipant, ILabelProvider, IHeaderContributor, IRequestableComponent, IHierarchical, IClusterable

public class Selectize extends FormComponent
Used to create a selectize.js choice component
Author:
Tobias Soloschenko
See Also:
  • Field Details

  • Constructor Details

    • Selectize

      public Selectize(String id)
    • Selectize

      public Selectize(String id, IModel<?> options)
      Creates a selectize component
      Parameters:
      id - the id of the component
      options - the options. If the model object value is instanceof String a tag representation is chosen. If the model object is instance of SelectizeOption a select representation is chosen.
    • Selectize

      public Selectize(String id, IModel<Collection<SelectizeOptionGroup>> optionGroups, IModel<?> options)
      Creates a selectize component
      Parameters:
      id - the id of the component
      optionGroups - the selectize groups, used for a select representation
      options - the selectize options, used for the selection in the select representation
  • Method Details

    • renderHead

      public void renderHead(IHeaderResponse response)
      Renders the required javascript / css libraries
      Specified by:
      renderHead in interface IHeaderContributor
      Overrides:
      renderHead in class Component
    • extendConfig

      protected com.github.openjson.JSONObject extendConfig(com.github.openjson.JSONObject config)
    • onComponentTag

      protected void onComponentTag(ComponentTag tag)
      Overrides:
      onComponentTag in class FormComponent
    • setDelimiter

      public void setDelimiter(String delimiter)
      Sets the delimiter (default is ",")
      Parameters:
      delimiter - the delimiter to be used
    • setTheme

      public void setTheme(SelectizeCssResourceReference.Theme theme)
      Sets the theme of the selectize component
      Parameters:
      theme - the theme
    • setPlaceholder

      public void setPlaceholder(String placeholder)
      Sets the placeholder
      Parameters:
      placeholder - the placeholder to be used
    • enableAjaxHandling

      public void enableAjaxHandling()
      Used to enable AJAX handling. Please override the following methods to provide data

      Method for response content: response(String)
      Method for template how to display: responseTemplate()
    • response

      protected SelectizeResponse response(String search)
      Provides the response and data for AJAX calls. Please ensure enableAjaxHandling() is invoked when overriding this method
      Parameters:
      search - the search query parameter the user typed into the text field
      Returns:
      the selectize response with a list of SelectizeOption's custom values can be applied with selectizeOption.put("key","value");
    • responseTemplate

      protected Component responseTemplate()
      Provides the template to be shown in the select result

      Important: The item (SelectizeOption) to refer to is named item!
      Important: The template uses handlebars template mechanism. To display the "text" value of the SelectizeOption use the following syntax:
       <div>{{text}}<div>
       
      It is also important that you always use a <div> element in the response panel which can be used of selectize to apply the selected class.

      Please ensure enableAjaxHandling() is invoked when overriding this method

      Returns:
      the Panel to be rendered in the template
    • onChange

      protected void onChange(AjaxRequestTarget target, String value)
      Is invoked when ever a user selected an option.

      Important:This method is only invoked when ajax is enabled
      Parameters:
      target - the ajax request target to apply changes
      value - the selected value
    • isCreateAvailable

      public boolean isCreateAvailable()
      If selectize is enabled to create entries
      Returns:
      if selectize is enabled to create entries
    • setCreateAvailable

      public void setCreateAvailable(boolean createAvailable)
      Set the selectize component to be enabled to create entries
      Parameters:
      createAvailable - if selectize is enabled to create entries
    • setDefaultModel

      public MarkupContainer setDefaultModel(IModel model)
      Specified by:
      setDefaultModel in interface IGenericComponent
      Overrides:
      setDefaultModel in class MarkupContainer