diff --git a/include/class.dynamic_forms.php b/include/class.dynamic_forms.php index 173b090587986ddf06c0acf6abe8147f357b6831..364d29dfa5ab14b83b054976841b3331aa5a0730 100644 --- a/include/class.dynamic_forms.php +++ b/include/class.dynamic_forms.php @@ -1155,10 +1155,17 @@ class SelectionField extends FormField { return $this->getList()->getForm(); } function getSubFields() { + $fields = new ListObject(array( + new TextboxField(array( + // XXX: i18n: Change to a better word when the UI changes + 'label' => '['.__('Abbrev').']', + 'id' => 'abb', + )) + )); $form = $this->getList()->getForm(); - if ($form) - return $form->getFields(); - return array(); + if ($form && ($F = $form->getFields())) + $fields->extend($F); + return $fields; } function toString($items) { @@ -1263,9 +1270,21 @@ class SelectionField extends FormField { } function getFilterData() { + // Start with the filter data for the list item as the [0] index $data = array(parent::getFilterData()); - if (($v = $this->getClean()) instanceof DynamicListItem) { - $data = array_merge($data, $v->getFilterData()); + if (($v = $this->getClean())) { + // Add in the properties for all selected list items in sub + // labeled by their field id + foreach ($v as $id=>$L) { + if (!($li = DynamicListItem::lookup($id))) + continue; + foreach ($li->getFilterData() as $prop=>$value) { + if (!isset($data[$prop])) + $data[$prop] = $value; + else + $data[$prop] .= " $value"; + } + } } return $data; } @@ -1295,9 +1314,9 @@ class TypeaheadSelectionWidget extends ChoicesWidget { foreach ($this->field->getList()->getItems() as $i) $source[] = array( 'value' => $i->getValue(), 'id' => $i->getId(), - 'info' => sprintf('%s %s', + 'info' => sprintf('%s%s', $i->getValue(), - (($extra= $i->getAbbrev()) ? "-- $extra" : '')), + (($extra= $i->getAbbrev()) ? " — $extra" : '')), ); ?> <span style="display:inline-block"> @@ -1318,6 +1337,7 @@ class TypeaheadSelectionWidget extends ChoicesWidget { $('input#<?php echo $this->name; ?>_id') .attr('name', '<?php echo $this->name; ?>[' + item['id'] + ']') .val(item['value']); + return false; } }); }); @@ -1336,8 +1356,12 @@ class TypeaheadSelectionWidget extends ChoicesWidget { function getEnteredValue() { // Used to verify typeahead fields $data = $this->field->getSource(); - if (isset($data[$this->name.'_name'])) - return trim($data[$this->name.'_name']); + if (isset($data[$this->name.'_name'])) { + // Drop the extra part, if any + $v = $data[$this->name.'_name']; + $v = substr($v, 0, strrpos($v, ' — ')); + return trim($v); + } return parent::getValue(); } } diff --git a/include/class.forms.php b/include/class.forms.php index e242a44ba40c77807e454be6f9b2313cabc6bb5f..3f2b68db2bab376312979cc3c1a1b60c69a037c0 100644 --- a/include/class.forms.php +++ b/include/class.forms.php @@ -594,17 +594,6 @@ class FormField { return null; } - /** - * Indicates if the field provides for searching for something other - * than keywords. For instance, textbox fields can have hits by keyword - * searches alone, but selection fields should provide the option to - * match a specific value or set of values and therefore need to - * participate on any search builder. - */ - function hasSpecialSearch() { - return true; - } - function getConfigurationForm($source=null) { if (!$this->_cform) { $type = static::getFieldType($this->get('type')); @@ -699,10 +688,6 @@ class TextboxField extends FormField { ); } - function hasSpecialSearch() { - return false; - } - function validateEntry($value) { parent::validateEntry($value); $config = $this->getConfiguration(); @@ -773,10 +758,6 @@ class TextareaField extends FormField { ); } - function hasSpecialSearch() { - return false; - } - function display($value) { $config = $this->getConfiguration(); if ($config['html']) @@ -829,10 +810,6 @@ class PhoneField extends FormField { ); } - function hasSpecialSearch() { - return false; - } - function validateEntry($value) { parent::validateEntry($value); $config = $this->getConfiguration(); @@ -1131,9 +1108,6 @@ class ThreadEntryField extends FormField { function isPresentationOnly() { return true; } - function hasSpecialSearch() { - return false; - } function getConfigurationOptions() { global $cfg; @@ -1454,10 +1428,6 @@ class FileUploadField extends FormField { ); } - function hasSpecialSearch() { - return false; - } - /** * Called from the ajax handler for async uploads via web clients. */ diff --git a/include/class.list.php b/include/class.list.php index f5f9c4bd2551f5605dc4228da9b827e6c62ac010..a54277533d6759711bfe768ba2601672fcd2ea05 100644 --- a/include/class.list.php +++ b/include/class.list.php @@ -587,6 +587,15 @@ class DynamicListItem extends VerySimpleModel implements CustomListItem { } } + function getFilterData() { + $data = array(); + foreach ($this->getConfigurationForm()->getFields() as $F) { + $data['.'.$F->get('id')] = $F->toString($F->value); + } + $data['.abb'] = (string) $this->get('extra'); + return $data; + } + function toString() { return $this->get('value'); }