PEAR logo

HTML_QuickForm_advmultiselect : The Definitive Guide



Live counters

Introduction
Identification and localisation

Introduction

When selection lists have lot of item, we don't expect to count each item one by one.

When it's so easy to count selections on server side, once the form is submitted, there is no ability to do the same in live, until new feature "Live counter".

[Important] Important
This feature require HTML_QuickForm_advmultiselect package version 1.3.0 or better.

A full example is given in appendices. See live counter combines with multiple elements.

Identification and localisation

Implements display of live counters (selected, unselected items) is fully independant. Its requires for each counter to add new placeholders.

For item unselected list, these placehodlers are :

  • {unselected_count} for localisation (where the counter value will be displayed)
  • {unselected_count_id} for identification by DOM API (ID attribut of any HTML tag)

For item selected list, these placehodlers are :

  • {selected_count} for localisation (where the counter value will be displayed)
  • {selected_count_id} for identification by DOM API (ID attribut of any HTML tag)
[Note] Note
  1. <?php
  2. require_once 'HTML/QuickForm.php';
  3. require_once 'HTML/QuickForm/advmultiselect.php';
  4. // ...
  5. $form = new HTML_QuickForm('amsLC');
  6. $ams =& $form->addElement('advmultiselect', 'cars', null, $car_array);
  7. // ...
  8. ?>

Counters identifiers (attribut ID) used by DOM API are identified by string : advmultiselect element name concat with "_selected" or "_unselected" suffix (depending of lists).

Result for example (previous code) : cars_selected or cars_unselected

advmultiselect element with single list (with checkboxes) are identified by string : "qfams_" prefix concat with advmultiselect element name

Result for example (previous code) : qfams_cars

advmultiselect element with double list are identified with string : prefix "__" (two underscores) concat with advmultiselect element name for unselected list. While selection list (selected item) is identified with string : prefix "_" (one underscore) concat with advmultiselect element name.

Result for example (previous code) : __cars et _cars

[Important] Important

advmultiselect elements with single list (with checkboxes) are identified by DOM API with only {selected_count} et {selected_count_id} placeholders. No need to add {unselected_count} and {unselected_count_id} placeholders.

See example in appendix Live counter combines with multiple elements, and template definition $template1 lines 49-57.

HTML_QuickForm_advmultiselect : The Definitive Guide v 1.4.0 : 9 Juin 2007