phpcontrols – 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>
]]>
enable_combobox() https://phpautocomplete.com/docs/enable_combobox/ Tue, 11 Feb 2014 22:29:36 +0000 http://phpautocomplete.com/?p=115 Enable combobox. It is disabled by default. By default, PHP Autocomplete only allows value from existing options in the dropdown. When combobox is enabled, new value can be added to the selection.

Signature:

public function enable_combobox(bool $enable = true )

Parameters:

  • $enable: true or false
]]>
enable_closeonselect() https://phpautocomplete.com/docs/enable_closeonselect/ Tue, 11 Feb 2014 21:29:36 +0000 http://phpautocomplete.com/?p=114 Whether to collapse the dropdown after a selection is made. Allows rapid selection in multi-select mode. Only applies in multi-select mode.

Signature:

public function enable_closeonselect(bool $closeOnSelect = true )

Parameters:

  • $closeOnSelect: Default to true
]]>
display() https://phpautocomplete.com/docs/display/ Tue, 11 Feb 2014 19:10:12 +0000 http://phpautocomplete.com/?p=109 Display the auto-complete control finally. When attached to <select>, set $tag to SELECT, or INPUT when attached to <input type=”hidden”>.This should be the LAST method to call.

Signature:

public function display(string $tag = 'INPUT', bool $script_include = true)

Parameters:

  • $tag: “SELECT” or “INPUT” (default to “INPUT”, case sensitive)
  • $script_include: true or false indicates whether to include required jQuery autocomplete JavaScript libraries (default to true).
]]>
disable_search() https://phpautocomplete.com/docs/disable_search/ Tue, 11 Feb 2014 19:05:08 +0000 http://phpautocomplete.com/?p=108 Disable search. This essentially removes the search from the dropdown. Disable search makes the control looks like a regular dropdown.

Note that when either set_max_input_length() or set_min_input_length() method is presented, disable_search() is ignored.

Signature:

public function disable_search()
]]>
add_event() https://phpautocomplete.com/docs/add_event/ Tue, 11 Feb 2014 18:57:32 +0000 http://phpautocomplete.com/?p=104 Add event handler. A typical use of this method is to pass Select2 event name, then a Javascript event handler function. Note that the generated Javascript methods is injected BEFORE end of $(document).ready(…)

Signature:

public function add_event(param1, param2, ....)

Parameter:

  • variable-length argument lists

A list of supported events:

  • change
  • select2-opening
  • select2-open
  • select2-close
  • select2-highlight
  • select2-selecting
  • select2-removing
  • select2-removed
  • select2-loaded
  • select2-focus
  • select2-blur
  • select2-clearing

Example:

$pac -> add_event('select2-close', 'function() { console.log("close"); }');
]]>
Constructor https://phpautocomplete.com/docs/constructor/ Tue, 11 Feb 2014 18:39:36 +0000 http://phpautocomplete.com/?p=102 PHP Autocomplete constructor takes two parameters and must attach to an existing HTML <select> tag, or a <input type=”hidden”>.

When attached to <input type=”hidden”>, use the second parameter to load from a data array.

Signature:

public function __constructor(string $sel_id, array $data )

Parameters:

  • $sel_id: The id attribute of either <select> or <input type=”hidden”> tag
  • $data: Initial data to load the dropdown (Hidden Input only)

Remark:

  • The $sel_id must have a corresponding <select> or <input type=”hidden”> tag with the exact same id.
  • The $sel_id must be unique

Example 1 (when attached to a <select> tag):

<?php
$pac = new C_PhpAutocomplete('foobar');
$pac -> display('SELECT');
?>
<select id="foobar" multiple>
    <option></option>
    <option id="1">Apple</option>
    <option id="2">Google</option>
    <option id="3">Microsoft</option>
    <option id="4">Facebook</option>
    <option id="5">Twitter</option>
</select>

Example 2 (when attached to a <input type=”hidden”> tag):

<?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('foobar');
$pac -> display('INPUT');
?>
<input id="foobar" type="hidden" />
]]>
Installation https://phpautocomplete.com/docs/installation/ Tue, 11 Feb 2014 18:24:30 +0000 http://phpautocomplete.com/?p=101 First and foremost, download the PHP Autocomplete from the download page, and then extract the zip file in your web server root folder.

In conf.php, simply set PAC_PATH representing the relative or absolute URL to the PHP Autocomplete library.

Assuming phpAutocomplete folder is inside the web root:

define('PAC_PATH','/phpAutocomplete/');

Then include conf.php in on top of the every page.

require_once("../conf.php");
]]>
System Requirements https://phpautocomplete.com/docs/system-requirements/ Tue, 11 Feb 2014 18:21:37 +0000 http://phpautocomplete.com/?p=100 PHP Autocomplete requires web server that supports PHP 5.3 and higher.

  • PHP 5.3 or later
  • Apache, Tomcat, or Microsoft IIS web server

PHP Autocomplete is prepackaged with required jQuery autocomplete Select2 Javascript libraries and server side components. Developers don’t have to download them separately. PHP Auto complete does not require a database to work.

]]>