diff --git a/wire/core/FieldtypeMulti.php b/wire/core/FieldtypeMulti.php index c32eaa81..7ed9ac2d 100644 --- a/wire/core/FieldtypeMulti.php +++ b/wire/core/FieldtypeMulti.php @@ -866,18 +866,24 @@ abstract class FieldtypeMulti extends Fieldtype { * */ public function getLoadQueryAutojoin(Field $field, DatabaseQuerySelect $query) { + $database = $this->wire()->database; if($this->get('useOrderByCols')) { // autojoin is not used if sorting or pagination is active $orderByCols = $field->get('orderByCols'); if(count($orderByCols) > 0) return null; } - $table = $this->database->escapeTable($field->table); - $schema = $this->trimDatabaseSchema($this->getDatabaseSchema($field)); - $fieldName = $this->database->escapeCol($field->name); + $table = $database->escapeTable($field->table); + $schemaAll = $this->getDatabaseSchema($field); + $schema = $this->trimDatabaseSchema($schemaAll); + $fieldName = $database->escapeCol($field->name); $separator = self::multiValueSeparator; - if($field->distinctAutojoin) $table = "DISTINCT $table"; + $orderBy = ''; + if($field->distinctAutojoin) { + if(isset($schemaAll['sort'])) $orderBy = "ORDER BY $table.sort"; + $table = "DISTINCT $table"; + } foreach($schema as $key => $unused) { - $query->select("GROUP_CONCAT($table.$key SEPARATOR '$separator') AS `{$fieldName}__$key`"); // QA + $query->select("GROUP_CONCAT($table.$key $orderBy SEPARATOR '$separator') AS `{$fieldName}__$key`"); // QA } return $query; } @@ -1039,5 +1045,3 @@ abstract class FieldtypeMulti extends Fieldtype { } } - - diff --git a/wire/modules/Inputfield/InputfieldPageAutocomplete/InputfieldPageAutocomplete.js b/wire/modules/Inputfield/InputfieldPageAutocomplete/InputfieldPageAutocomplete.js index 08279d7a..2a0547e2 100644 --- a/wire/modules/Inputfield/InputfieldPageAutocomplete/InputfieldPageAutocomplete.js +++ b/wire/modules/Inputfield/InputfieldPageAutocomplete/InputfieldPageAutocomplete.js @@ -241,7 +241,8 @@ var InputfieldPageAutocomplete = { // items: '.InputfieldPageListSelectMultiple ol > li', axis: 'y', update: function(e, data) { - InputfieldPageAutocomplete.rebuildInput($(this)); + InputfieldPageAutocomplete.rebuildInput($(this)); + InputfieldPageAutocomplete.triggerChange($ol) $ol.trigger('sorted', [ data.item ]); }, start: function(e, data) { diff --git a/wire/modules/Inputfield/InputfieldPageAutocomplete/InputfieldPageAutocomplete.module b/wire/modules/Inputfield/InputfieldPageAutocomplete/InputfieldPageAutocomplete.module index 4ed5ab8d..04950cb9 100644 --- a/wire/modules/Inputfield/InputfieldPageAutocomplete/InputfieldPageAutocomplete.module +++ b/wire/modules/Inputfield/InputfieldPageAutocomplete/InputfieldPageAutocomplete.module @@ -322,12 +322,21 @@ class InputfieldPageAutocomplete extends Inputfield implements InputfieldHasArra $pps->setDisplayFormat($name, $this->labelFieldFormat, true); $queryStrings[] = "format_name=$name"; } + + // optional extra data set in session in case any hooks need it. + // how to retrieve when ProcessPageSearch is $this->process + // $name = $input->get->fieldName('format_name'); + // $data = $process->getForSelector($name, true); + $data = array( + 'page_id' => ($this->hasPage ? $this->hasPage->id : 0), + 'field' => ($this->hasField ? $this->hasField->name : ''), + ); $queryStrings[] = 'get=' . urlencode($this->labelFieldName); // tell ProcessPageSearch to store this selector which we can tell it to use // by setting $_GET['for_selector_name'] = $name - $url = $pps->setForSelector($name, trim($selector, ', ')); + $url = $pps->setForSelector($name, trim($selector, ', '), $data); if(count($queryStrings)) $url .= '&' . implode('&', $queryStrings); // replace any pipes with encoded version