mirror of
https://github.com/silverstripe/silverstripe-tagfield
synced 2024-10-22 09:05:32 +00:00
Merge pull request #81 from robbieaverill/feature/apply-can-create-to-select2
Apply canCreate permissions to Select2 for tags
This commit is contained in:
commit
35773d4a56
@ -164,6 +164,8 @@ class StringTagField extends DropdownField
|
||||
));
|
||||
}
|
||||
|
||||
$this->setAttribute('data-can-create', (int) $this->getCanCreate());
|
||||
|
||||
return $this
|
||||
->customise($properties)
|
||||
->renderWith(array("templates/TagField"));
|
||||
|
@ -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();
|
||||
|
@ -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'),
|
||||
|
Loading…
x
Reference in New Issue
Block a user