mirror of
https://github.com/silverstripe/silverstripe-tagfield
synced 2024-10-22 11:05:32 +02:00
BUGFIX: Get TagField working in the ModelAdmin.
FEATURE: Make tagObjectField editable in the constructor.
This commit is contained in:
parent
9cb4624d1a
commit
4ad3adb128
@ -73,8 +73,9 @@ class TagField extends TextField {
|
||||
*/
|
||||
protected $customTags;
|
||||
|
||||
function __construct($name, $title = null, $value = null, $tagTopicClass = null) {
|
||||
function __construct($name, $title = null, $value = null, $tagTopicClass = null, $tagObjectField = "Title") {
|
||||
$this->tagTopicClass = $tagTopicClass;
|
||||
$this->tagObjectField = $tagObjectField;
|
||||
|
||||
parent::__construct($name, $title, $value);
|
||||
}
|
||||
@ -85,22 +86,25 @@ class TagField extends TextField {
|
||||
Requirements::javascript("tagfield/javascript/jquery.tags.js");
|
||||
Requirements::css("tagfield/css/TagField.css");
|
||||
|
||||
if($this->customTags) {
|
||||
Requirements::customScript("jQuery(document).ready(function() {
|
||||
jQuery('#" . $this->id() . "').tagSuggest({
|
||||
tags: " . Convert::raw2json($this->customTags) . "
|
||||
});
|
||||
});");
|
||||
} else {
|
||||
Requirements::customScript("jQuery(document).ready(function() {
|
||||
jQuery('#" . $this->id() . "').tagSuggest({
|
||||
url: '" . parse_url($this->Link(),PHP_URL_PATH) . "/suggest',
|
||||
separator: '" . $this->separator . "'
|
||||
});
|
||||
});");
|
||||
}
|
||||
// Standard textfield stuff
|
||||
$attributes = array(
|
||||
'type' => 'text',
|
||||
'class' => 'text tagField',
|
||||
'id' => $this->id(),
|
||||
'name' => $this->Name(),
|
||||
'value' => $this->Value(),
|
||||
'tabindex' => $this->getTabIndex(),
|
||||
'maxlength' => ($this->maxLength) ? $this->maxLength : null,
|
||||
'size' => ($this->maxLength) ? min( $this->maxLength, 30 ) : null,
|
||||
);
|
||||
if($this->disabled) $attributes['disabled'] = 'disabled';
|
||||
|
||||
return parent::Field();
|
||||
// Data passed as custom attributes
|
||||
if($this->customTags) $attributes['tags'] = $this->customTags;
|
||||
else $attributes['href'] = parse_url($this->Link(),PHP_URL_PATH);
|
||||
$attributes['rel'] = $this->separator;
|
||||
|
||||
return $this->createTag('input', $attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -242,7 +246,7 @@ class TagField extends TextField {
|
||||
);
|
||||
if($this->tagFilter) $SQL_filter .= ' AND ' . $this->tagFilter;
|
||||
|
||||
$tagObjs = DataObject::get($tagClass, $SQL_filter, $this->tagSort);
|
||||
$tagObjs = DataObject::get($tagClass, $SQL_filter, $this->tagSort, "", 50);
|
||||
$tagArr = ($tagObjs) ? array_values($tagObjs->map('ID', $this->tagObjectField)) : array();
|
||||
|
||||
return $tagArr;
|
||||
|
@ -131,7 +131,7 @@
|
||||
for (i = 0; i < matches.length; i++) {
|
||||
html += '<' + settings.tagWrap + ' class="_tag_suggestion">' + matches[i] + '</' + settings.tagWrap + '>';
|
||||
}
|
||||
|
||||
|
||||
tagMatches.html(html);
|
||||
suggestionsShow = !!(matches.length);
|
||||
} else {
|
||||
@ -264,4 +264,26 @@
|
||||
setSelection();
|
||||
});
|
||||
};
|
||||
|
||||
// SilverStripe loader
|
||||
SSTagFieldLoader = function() {
|
||||
$('input.tagField').each(function() {
|
||||
var tags;
|
||||
if(tags = $(this).attr('taglist')) {
|
||||
$(this).tagSuggest({
|
||||
tags: tags,
|
||||
separator: $(this).attr('rel')
|
||||
});
|
||||
} else {
|
||||
$(this).tagSuggest({
|
||||
url: $(this).attr("href") + '/suggest',
|
||||
separator: $(this).attr('rel')
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if(typeof $(document).livequery != 'undefined') $(document).livequery(SSTagFieldLoader);
|
||||
else $(document).ready(SSTagFieldLoader);
|
||||
|
||||
})(jQuery);
|
Loading…
Reference in New Issue
Block a user