Commit cd850266 authored by Elias Villiger's avatar Elias Villiger
Browse files

Fixes #5444. Typeahead FE value is now prefetched after save.

parent 0a83cde2
Pipeline #5020 passed with stages
in 6 minutes and 19 seconds
......@@ -11,6 +11,7 @@ namespace IMATHUZH\Qfq\Core;
use IMATHUZH\Qfq\Core\Database\Database;
use IMATHUZH\Qfq\Core\Form\Checkbox;
use IMATHUZH\Qfq\Core\Form\FormAsFile;
use IMATHUZH\Qfq\Core\Form\TypeAhead;
use IMATHUZH\Qfq\Core\Helper\HelperFile;
use IMATHUZH\Qfq\Core\Helper\HelperFormElement;
use IMATHUZH\Qfq\Core\Helper\KeyValueStringParser;
......@@ -846,6 +847,12 @@ abstract class AbstractBuildForm {
// Retrieve value via FSRVD
$sanitizeClass = ($mode == FORM_UPDATE) ? SANITIZE_ALLOW_ALL : $formElement[FE_CHECK_TYPE];
$value = $this->store->getVar($name, $storeUse, $sanitizeClass, $foundInStore);
// For typeAhead fields: perform prefetch to display description instead of key (#5444)
if ($mode == FORM_SAVE && isset($fe[FE_TYPEAHEAD_SQL_PREFETCH])) {
$config = [FE_TYPEAHEAD_SQL_PREFETCH => $fe[FE_TYPEAHEAD_SQL_PREFETCH]];
$value = TypeAhead::typeAheadSqlPrefetch($config, $value, $this->dbArray[$this->dbIndexData]);
}
}
if ($formElement[FE_ENCODE] === FE_ENCODE_SPECIALCHAR) {
......
......@@ -83,7 +83,7 @@ class TypeAhead {
if($this->vars[TYPEAHEAD_API_PREFETCH] == '') {
$arr = $this->typeAheadSql($sipVars, $this->vars[TYPEAHEAD_API_QUERY]);
} else {
$arr = $this->typeAheadSqlPrefetch($sipVars, $this->vars[TYPEAHEAD_API_PREFETCH]);
$arr = $this->typeAheadSqlPrefetch($sipVars, $this->vars[TYPEAHEAD_API_PREFETCH], $this->db);
}
} elseif (isset($sipVars[FE_LDAP_SERVER])) {
$ldap = new Ldap();
......@@ -155,7 +155,7 @@ class TypeAhead {
* @throws \UserFormException
*/
private function typeAheadSqlPrefetch(array $config, $key) {
public static function typeAheadSqlPrefetch(array $config, $key, $db) {
$keys = array();
$sql = $config[FE_TYPEAHEAD_SQL_PREFETCH];
......@@ -172,7 +172,7 @@ class TypeAhead {
$keys[] = $key;
}
$arr = $this->db->sql($sql, ROW_REGULAR, $keys);
$arr = $db->sql($sql, ROW_REGULAR, $keys);
if ($arr == false || count($arr) == 0) {
return array();
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment