PHP Autocomplete https://phpautocomplete.com The Ultimate PHP Dropdown Thu, 09 Feb 2023 22:25:48 +0000 en-US hourly 1 https://wordpress.org/?v=7.0.4 Lock, Disable Selection https://phpautocomplete.com/examples/lock-disable-selection/ Wed, 12 Mar 2014 06:13:55 +0000 http://phpautocomplete.com/?p=232 true when calling set_init_selection(). Note that lock a selection is only possible when multiple selection is enabled. To disable a selection from selected in the dropdown, add “disabled”=>true to the data source. […]]]> In the event that you need to lock certain selections so that they can’t be removed, you can now pass in “locked” => true when calling set_init_selection(). Note that lock a selection is only possible when multiple selection is enabled.

To disable a selection from selected in the dropdown, add “disabled”=>true to the data source.

In the following example, the selection “Microsoft” is disabled.

<?php
$data = array(array('id'=>1, 'text'=>'Apple'),
    array('id'=>2, 'text'=>'Google'),
    array('id'=>3, 'text'=>'Microsoft', 'disabled'=>true),
    array('id'=>4, 'text'=>'Facebook'),
    array('id'=>5, 'text'=>'Twitter'));

$pac = new C_PhpAutocomplete('lock_selection_INPUT', $data);
$pac->enable_multiple(true);    // hidden input only
$pac->set_init_selection(array(
    array("id"=>"1", "text"=>"Apple"),
    array("id"=>"5", "text"=>"Twitter", "locked"=>true)));
$pac->display();
?>
<input id="lock_selection_INPUT" type="hidden" value="" />
]]>
Set Initial Selection https://phpautocomplete.com/examples/set-initial-selection/ Wed, 12 Mar 2014 06:01:30 +0000 http://phpautocomplete.com/?p=231 To set initial selected value during page load, use set_init_selection() method. The parameter must be an object array with both “id” and “text” properties. You can use it to set initial selected value for both <select> and <input type=”hidden”>, single or multiple selection.

For example:

$pac->set_init_selection(array(
                            array("id"=>"1", "text"=>"Apple"),
                            array("id"=>"5", "text"=>"Twitter")));

Example: Set initial multiple selection for <input type=”hidden”>

<?php
$data = array(array('id'=>1, 'text'=>'Apple'),
    array('id'=>2, 'text'=>'Google'),
    array('id'=>3, 'text'=>'Microsoft'),
    array('id'=>4, 'text'=>'Facebook'),
    array('id'=>5, 'text'=>'Twitter'));

$pac = new C_PhpAutocomplete('init_selection_INPUT', $data);
$pac->enable_multiple(true);    // hidden input only
$pac->set_init_selection(array(
                            array("id"=>"1", "text"=>"Apple"),
                            array("id"=>"5", "text"=>"Twitter")));
$pac->display();
?>
<input id="init_selection_INPUT" type="hidden" value="" />

<script>
    function get_init_selection(ctrl_id){
        alert($(ctrl_id).select2("val"));
        return false;
    };
</script>
<a href="#" onclick="get_init_selection('#init_selection_INPUT2')">show selected value</a>
]]>
set_init_selection() https://phpautocomplete.com/docs/set_init_selection-2/ Fri, 14 Feb 2014 17:56:43 +0000 http://phpautocomplete.com/?p=145 Set initial selected value during page load. It can be a single or multiple values. The parameter must be an object array. You can also call readonly and enable properties with this method. See example for usage detail.

Signature:

public function set_init_selection(array $val)

Parameters:

  • $val: – An object array
]]>
set_tags() https://phpautocomplete.com/docs/set_tags/ Fri, 14 Feb 2014 17:55:50 +0000 http://phpautocomplete.com/?p=148 Select from existing tags or create a new tag. Tags are the simplest form of data where the id is also the text. Take an array representing a list of tags. User can select from existing tags or create a new tag by picking the first choice which is what the user has typed into the search box.

Note that when tagging is enabled the user can select from pre-existing tags or create a new tag by picking the first choice which is what the user has typed into the search box so far.

Signature:

public function set_tags(array $tags, array $tokenSeparators)

Parameters:

  • $tags: Array
  • $tokenSeparators: An array of strings that define token separators.
]]>
set_sort_results() https://phpautocomplete.com/docs/set_sort_results/ Fri, 14 Feb 2014 17:54:15 +0000 http://phpautocomplete.com/?p=147 Sorting displayed results. Sort the results list for searching before the results are displayed. Useful for sorting matches by relevance to the user’s search term.

Enter “length” to sort by length of characters, or “alpha” to sort alphabetically.

Signature:

public function set_sort_results(mixed $sort_func)

Parameters:

  • $sort_func: custom JavaScript sort function
]]>
set_separator() https://phpautocomplete.com/docs/set_separator/ Fri, 14 Feb 2014 17:53:26 +0000 http://phpautocomplete.com/?p=146 Separator character or string used to delimit ids in value attribute of the multi-valued selects. The default delimiter is the “,” character.

Signature:

public function set_separator(mixed $separator)

Parameters:

  • $separator: character(s).
]]>
set_query() https://phpautocomplete.com/docs/set_query/ Fri, 14 Feb 2014 17:52:36 +0000 http://phpautocomplete.com/?p=144 Use JavaScript function to load data. It can be used to add options dynamically. Applies to <input type=”hidden”> only.

Signature:

public function set_query($query_func)

Parameters:

  • $query_func
]]>
set_placeholder() https://phpautocomplete.com/docs/set_placeholder/ Fri, 14 Feb 2014 17:51:13 +0000 http://phpautocomplete.com/?p=143 Initial value selected if no other selection is made.

Signature:

public function set_placeholder(string $placeholder = ' ', bool $allowClear = true)

Parameters:

  • $placeholder: Placeholder text, e.g. “Please make a selection:”
  • $allowClear: Whether to display a clear button “x” to clear the select box back to the placeholder value once a selection is made.
]]>
set_min_input_length() https://phpautocomplete.com/docs/set_min_input_length/ Fri, 14 Feb 2014 17:50:29 +0000 http://phpautocomplete.com/?p=142 Minimum number of characters required to start a search. System default is 0 (no minimum restriction).

Signature:

public function set_min_input_length(integer $minimumInputLength = 2)

Parameters:

  • $minimumInputLength: Minimum input length
]]>
set_max_input_length() https://phpautocomplete.com/docs/set_max_input_length/ Fri, 14 Feb 2014 17:49:51 +0000 http://phpautocomplete.com/?p=141 Maximum number of characters that can be entered to start a search. System default is 10 characters.

Signature:

public function set_max_input_length(integer $maximumInputLength = 10)

Parameters:

  • $maximumInputLength: Maximum input length
]]>