Merge pull request #81 from robbieaverill/feature/apply-can-create-to-select2

Apply canCreate permissions to Select2 for tags
This commit is contained in:
Christopher Pitt 2016-08-08 14:31:09 +12:00 committed by GitHub
commit 35773d4a56
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'),