Apply canCreate permissions to Select2 for tags

* Resolves #80
This commit is contained in:
Robbie Averill 2016-07-22 08:52:17 +12:00
parent d3563cebbc
commit e3c42727e4
3 changed files with 13 additions and 5 deletions

View File

@ -164,6 +164,8 @@ class StringTagField extends DropdownField
));
}
$this->setAttribute('data-can-create', (int) $this->getCanCreate());
return $this
->customise($properties)
->renderWith(array("templates/TagField"));

View File

@ -178,6 +178,8 @@ class TagField extends DropdownField
));
}
$this->setAttribute('data-can-create', (int) $this->getCanCreate());
return $this
->customise($properties)
->renderWith(array("templates/TagField"));
@ -406,7 +408,7 @@ class TagField extends DropdownField
{
return true;
}
/**
* Converts the field to a readonly variant.
*
@ -429,7 +431,7 @@ class TagField extends DropdownField
class TagField_Readonly extends TagField
{
protected $readonly = true;
/**
* Render the readonly field as HTML.
*
@ -439,13 +441,13 @@ class TagField_Readonly extends TagField
public function Field($properties = array())
{
$options = array();
foreach ($this->getOptions()->filter('Selected', true) as $option) {
$options[] = $option->Title;
}
$field = ReadonlyField::create($this->name.'_Readonly', $this->title);
$field->setForm($this->form);
$field->setValue(implode(', ', $options));
return $field->Field();

View File

@ -46,6 +46,10 @@
'tokenSeparators': [',']
};
if ($select.attr('data-can-create') == 0) {
options.tags = false;
}
if ($select.attr('data-ss-tag-field-suggest-url')) {
options.ajax = {
'url': $select.attr('data-ss-tag-field-suggest-url'),