There are 5 MarkupDynamicSelects methods that you will interact with in your template file in order to successfully output a Dynamic Selects. Please note that you can output as many Dynamic Selects as you wish in any one template file. The 5 methods are introduced below.
This method takes one non-optional argument $input. As the name suggests, it processes ajax-calls for data to populate a dependent select. $input here is a ProcessWire input.
This method accepts no arguments. It is optional to use. It simply renders some basic CSS to style your Dynamic Selects.
The default options are:
// default options $defaultOptions = array( // by default we post ajax calls to the current page 'ajaxURL' => './', // error message to be returned if data not returned by server 'fetchError' => $this->_('Dynamic Selects: There was an error fetching data'), );
You can override any of the two default options by passing your own array to the method, for instance:
// custom options $options = array( // custom ajax-handler page 'ajaxURL' => '/products/electronics/', // custom error message 'fetchError' => ('Dropdowns: We encountered an error and could not fetching results'), ); echo renderConfigs($options);
This method is responsible for rendering Dynamic Selects on the page. It is the gateway to the Dynamic Selects created in ProcessDynamicSelects. The method accepts two arguments, the first of which is not optional.
The first argument $dynamicSelects tells the method what Dynamic Selects built and configured using ProcessDynamicSelects to display. Please note that depending your settings, a given user (e.g. 'guest') might not be able to view the Dynamic Selects. The value of the first argument can either be a:
- Page: A Page Object of the Dynamic Selects.
- ID: The (integer) ID of the Dynamic Selects page.
- Title: The title of the Dynamic Selects page.
- Name: The name of the Dynamic Selects page.
- Array: The settings of the Dynamic Selects. These are saved in ds_settings as a JSON string.
The second argument is boolean. The default is false. If set to true, it will, in addition to rendering the Dynamic Selects, dynamically render an ordered list showing the returned results and their respective IDs for the currently triggered dependent select. This is used for debugging purposes only and is not useful for production. More details about debugging can be found in this topic.
A complete template file example is shown below. Please see the inline comments.