Skip to content

Commit

Permalink
Merge pull request #81 from robbieaverill/feature/apply-can-create-to…
Browse files Browse the repository at this point in the history
…-select2

Apply canCreate permissions to Select2 for tags
  • Loading branch information
assertchris authored Aug 8, 2016
2 parents d3563ce + e3c4272 commit 35773d4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 2 additions & 0 deletions code/StringTagField.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ public function Field($properties = array())
));
}

$this->setAttribute('data-can-create', (int) $this->getCanCreate());

return $this
->customise($properties)
->renderWith(array("templates/TagField"));
Expand Down
12 changes: 7 additions & 5 deletions code/TagField.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ public function Field($properties = array())
));
}

$this->setAttribute('data-can-create', (int) $this->getCanCreate());

return $this
->customise($properties)
->renderWith(array("templates/TagField"));
Expand Down Expand Up @@ -406,7 +408,7 @@ public function validate($validator)
{
return true;
}

/**
* Converts the field to a readonly variant.
*
Expand All @@ -429,7 +431,7 @@ public function performReadonlyTransformation()
class TagField_Readonly extends TagField
{
protected $readonly = true;

/**
* Render the readonly field as HTML.
*
Expand All @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions js/TagField.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down

0 comments on commit 35773d4

Please sign in to comment.