diff --git a/app/src/Lib/Traits/SearchFilterTrait.php b/app/src/Lib/Traits/SearchFilterTrait.php index 4fe68b7b8..34f1d5bc4 100644 --- a/app/src/Lib/Traits/SearchFilterTrait.php +++ b/app/src/Lib/Traits/SearchFilterTrait.php @@ -268,7 +268,7 @@ public function getSearchableAttributes(string $controller, \DateTimeZone $vv_tz 'type' => 'search', 'fieldName' => $field, 'personType' => $f['picker']['type'], - 'htmlId' => $field, // This is the input ID + 'htmlId' => Inflector::dasherize($field) . '-picker', // This is the input ID 'viewConfigParameters' => $f['picker']['configuration'] ]; $this->viewVars['vv_autocomplete_arguments'] = $autocompleteArgs; diff --git a/app/src/View/Helper/FieldHelper.php b/app/src/View/Helper/FieldHelper.php index b022abca4..5e674a06c 100644 --- a/app/src/View/Helper/FieldHelper.php +++ b/app/src/View/Helper/FieldHelper.php @@ -256,7 +256,7 @@ public function constructSPAField(string $element, string $vueElementName): stri if(!empty($matchesId[0][1]) && !empty($matchesName[0][1])) { $vueElementProperties = [ - 'htmlId' => $matchesId[0][1], + 'htmlId' => $matchesId[0][1] . '-picker', 'fieldName' => $matchesName[0][1], 'containerClasses' => $matchesClass[0][1], 'type' => 'field', diff --git a/app/templates/element/filter/filter.php b/app/templates/element/filter/filter.php index a6c94022b..bd8a1b99e 100644 --- a/app/templates/element/filter/filter.php +++ b/app/templates/element/filter/filter.php @@ -35,9 +35,11 @@ const filterForm = document.getElementById("top-filters-form"); filterForm.addEventListener('formdata', (event) => { if(event.formData.has('person_id')) { - const personId = $(filterForm).find('#person_id')[0].getAttribute('datapersonid') + const personId = $(filterForm).find('#person-id-picker')[0].getAttribute('datapersonid') if(personId != undefined && personId != '') { event.formData.set('person_id', personId) + } else { + event.formData.delete('person_id') } } }); diff --git a/app/templates/element/filter/topButtons.php b/app/templates/element/filter/topButtons.php index e5cea0050..b56107bd8 100644 --- a/app/templates/element/filter/topButtons.php +++ b/app/templates/element/filter/topButtons.php @@ -35,6 +35,9 @@ // to store the correct identifier in the case of dates. Dates have two search fields for each column // which makes it more complicated to keep track of the id. $data_identifier = is_array($params) ? implode(':', array_keys($params)) : $key; +if ($data_identifier === 'person_id') { + $data_identifier = 'person_id_picker'; +} // The populated variables are in plural while the column names are singular // Convention: It is a prerequisite that the vvar should be the plural of the column name diff --git a/app/templates/element/javascript.php b/app/templates/element/javascript.php index 5a7d9ecac..472b1a64b 100644 --- a/app/templates/element/javascript.php +++ b/app/templates/element/javascript.php @@ -159,6 +159,8 @@ let ident_to_snake = ident.replace(/_/g, "-"); let filterId = '#' + ident_to_snake; $(filterId).val(""); + // This will only apply to the people picker field + $(filterId).attr('datapersonid', ''); }); $(this).closest('form').submit(); diff --git a/app/templates/element/peopleAutocomplete.php b/app/templates/element/peopleAutocomplete.php index c545e7b1f..148abd0ec 100644 --- a/app/templates/element/peopleAutocomplete.php +++ b/app/templates/element/peopleAutocomplete.php @@ -37,7 +37,7 @@ $fieldName = $fieldName ?? 'person_id'; // Used by the SearchFilter Configuration $personType = $personType ?? 'person'; - $htmlId = $htmlId ?? 'cmPersonPickerId'; + $htmlId = $htmlId ?? 'person-id-picker'; // Does it have a value already. Default or stored // CAKEPHP automatically generates a select element if the value is an integer. This is not helpful here. $inputValue = $inputValue ?? $vv_field_arguments["fieldOptions"]["default"] ?? $vv_field_arguments["fieldOptions"]["value"] ?? ''; @@ -63,6 +63,20 @@ $personRecord = $this->Petition->getRecordForId('person_id', $inputValue, ['PrimaryName', 'EmailAddresses']); $canvasUrl = $this->Url->build(['controller' => 'people', 'action' => 'edit', $inputValue]); } + $searchPeople = $this->request->getAttribute('webroot') . 'api/ajax/v2/people/pick?co_id=' . $vv_cur_co->id; + if (isset($vv_petition->id)) { + $searchPeople = $this->request->getAttribute('webroot') . 'api/ajax/v2/people/pick?co_id=' . $vv_cur_co->id . '&petition_id=' . $vv_petition->id; + } + + // This is the actual field that will be submitted. + print $this->Form->control($fieldName, [ + 'id' => $fieldName, + 'value' => '', + 'type' => 'text', + 'class' => 'visually-hidden', + 'label' => false, + ] + ); ?>