use data ttribute for autocompletion

this moves the whole field creation to a separate function and adds the
full qualified column name as a data attribute. This is needed because
we can not rely on the field's name to figure out the column name as it
will be unrelated in bureaucracy use
This commit is contained in:
Andreas Gohr
2016-03-30 10:37:51 +02:00
parent fbc72efb40
commit ed3de3d67c
3 changed files with 43 additions and 22 deletions

View File

@ -13,6 +13,7 @@ use plugin\struct\meta\Assignments;
use plugin\struct\meta\SchemaData;
use plugin\struct\meta\ValidationException;
use plugin\struct\meta\Validator;
use plugin\struct\meta\Value;
use plugin\struct\types\AbstractBaseType;
/**
@ -220,11 +221,26 @@ class action_plugin_struct_entry extends DokuWiki_Action_Plugin {
// posted data trumps stored data
$field->setValue($postdata[$label]);
}
$html .= self::makeField($field, self::$VAR . "[$tablename][$label]");
}
$html .= '</fieldset>';
return $html;
}
/**
* Create the input field
*
* @param Value $field
* @param String $name field's name
* @return string
*/
static public function makeField(Value $field, $name) {
$trans = hsc($field->getColumn()->getTranslatedLabel());
$hint = hsc($field->getColumn()->getTranslatedHint());
$class = $hint ? 'hashint' : '';
$colname = $field->getColumn()->getFullQualifiedLabel();
$name = self::$VAR . "[$tablename][$label]";
$input = $field->getValueEditor($name);
// we keep all the custom form stuff the field might produce, but hide it
@ -234,17 +250,14 @@ class action_plugin_struct_entry extends DokuWiki_Action_Plugin {
$hide = '';
}
$html .= "<label $hide>";
$html = '';
$html .= "<label $hide data-column=\"$colname\">";
$html .= "<span class=\"label $class\" title=\"$hint\">$trans</span>";
$html .= "<span class=\"input\">$input</span>";
$html .= '</label>';
}
$html .= '</fieldset>';
return $html;
}
}
// vim:ts=4:sw=4:et:

11
helper/field.php Normal file
View File

@ -0,0 +1,11 @@
<?php
/**
* Allows adding a struct field as a bureaucracy field
*/
class helper_plugin_struct_field extends helper_plugin_bureaucracy_field {
}

View File

@ -86,10 +86,7 @@ jQuery(function () {
jQuery('input.struct_autocomplete').autocomplete({
ismulti: false,
source: function (request, cb) {
var name = this.element.attr('name');
name = name.substring(19, name.length - 1);
name = name.replace('][', '.');
var name = jQuery(this.element[0]).closest('label').data('column');
var term = request.term;
if (this.options.ismulti) {
term = extractLast(term);