Combo Box Fields

Introduction

A combo box field contains several text items which are displayed in a drop-down list. The selected value is displayed in a text box. It is also possible to allow editing the text box value, so that other options than the predefined are usable. 

The combo box field is represented by the SetaPDF_FormFiller_Field_Combo class. 

Setting and Getting Values

The SetaPDF_FormFiller_Field_Combo class offers, as any other field implementation, the getValue() and setValue() methods:

getValue()

Get the current value

setValue()

Set the fields value / Selects the option

The options of a list can have an export value and a visible value. Following method could be used to get the visible value:  

getVisibleValue()

Get the visible value of the current selected option

To get the complete options list following method is available:

getOptions()

Get the options and the export values.

Field Type Specific Properties

Editable

A combo box can receive other values than predefined in the option lists. This behavior can be controlled with the following methods:

isEditable()

Checks if the combo box shall include an editable text box as well to a drop-down list

setEditable()

Sets if the combo box shall include an editable text box as well to a drop-down list

Examples

PHP
// get the fields
$fields = $formFiller->getFields();
 
$comboField = $fields->get('a simple combo field');
$options = $comboField->getOptions();
foreach ($options AS $index => $optionData) {
    echo 'Option ' . $index . "\n";
    echo 'Visible value: ' . $optionData['visibleValue'] . "\n";
    echo 'Export value: ' . $optionData['exportValue'] . "\n";
}
 
$comboField->setValue(2); // select option with index 2
 
$editable = $fields->get('editable');
if ($editable->isEditable()) {
    $editable->setValue('any text will be accepted');
} else {
    $editable->setValue('an available export value');
}