Skip to content

Commit

Permalink
Fixed #3676
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Jan 21, 2019
1 parent 7762d81 commit 0a23f29
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Fixed
- Fixed an error that occurred when updating to Craft 3.1 if a plugin or module was calling any soft-deletable records’ `find()` methods.
- Fixed an error that occurred when updating from Craft 2 to Craft 3.1 if there were any RichText fields. ([#3677](https://github.com/craftcms/cms/issues/3677))
- Fixed a bug where it was possible to create duplicate tags by searching for and selecting the same tag name twice in the same Tags field. ([#3676](https://github.com/craftcms/cms/issues/3676))

## 3.1.2.2 - 2019-01-19

Expand Down
11 changes: 8 additions & 3 deletions src/controllers/TagsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,11 @@ public function actionSearchForTags(): Response
$tags = Tag::find()
->groupId($tagGroupId)
->title(Db::escapeParam($search) . '*')
->where(['not', ['elements.id' => $excludeIds]])
->all();

$return = [];
$exactMatches = [];
$excludes = [];
$tagTitleLengths = [];
$exactMatch = false;

Expand All @@ -201,9 +201,12 @@ public function actionSearchForTags(): Response
}

foreach ($tags as $tag) {
$exclude = in_array($tag->id, $excludeIds, false);

$return[] = [
'id' => $tag->id,
'title' => $tag->title
'title' => $tag->title,
'exclude' => $exclude,
];

$tagTitleLengths[] = StringHelper::length($tag->title);
Expand All @@ -220,9 +223,11 @@ public function actionSearchForTags(): Response
} else {
$exactMatches[] = 0;
}

$excludes[] = $exclude ? 1 : 0;
}

array_multisort($exactMatches, SORT_DESC, $tagTitleLengths, $return);
array_multisort($excludes, SORT_ASC, $exactMatches, SORT_DESC, $tagTitleLengths, $return);

return $this->asJson([
'tags' => $return,
Expand Down
26 changes: 19 additions & 7 deletions src/web/assets/cp/dist/js/Craft.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! - 2019-01-15 */
/*! - 2019-01-21 */
(function($){

/** global: Craft */
Expand Down Expand Up @@ -18561,16 +18561,23 @@ Craft.TagSelectInput = Craft.BaseElementSelectInput.extend(
var $li;

for (var i = 0; i < response.tags.length; i++) {
$li = $('<li/>').appendTo($ul);
$('<a data-icon="tag"/>').appendTo($li).text(response.tags[i].title).data('id', response.tags[i].id);
$li = $('<li/>')
.appendTo($ul)
.addClass(response.tags[i].exclude ? 'disabled' : '');

$('<a data-icon="tag"/>')
.appendTo($li)
.text(response.tags[i].title)
.data('id', response.tags[i].id)
.addClass(response.tags[i].exclude ? 'disabled' : '');
}

if (!response.exactMatch) {
$li = $('<li/>').appendTo($ul);
$('<a data-icon="plus"/>').appendTo($li).text(data.search);
}

$ul.find('> li:first-child > a').addClass('hover');
$ul.find('> li:not(.disabled):first > a').addClass('hover');

this.searchMenu = new Garnish.Menu($menu, {
attachToElement: this.$addTagInput,
Expand All @@ -18592,9 +18599,14 @@ Craft.TagSelectInput = Craft.BaseElementSelectInput.extend(
},

selectTag: function(option) {
var $option = $(option),
id = $option.data('id'),
title = $option.text();
var $option = $(option);

if ($option.hasClass('disabled')) {
return;
}

var id = $option.data('id');
var title = $option.text();

var $element = $('<div/>', {
'class': 'element small removable',
Expand Down
2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/js/Craft.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/js/Craft.min.js.map

Large diffs are not rendered by default.

24 changes: 18 additions & 6 deletions src/web/assets/cp/src/js/TagSelectInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,23 @@ Craft.TagSelectInput = Craft.BaseElementSelectInput.extend(
var $li;

for (var i = 0; i < response.tags.length; i++) {
$li = $('<li/>').appendTo($ul);
$('<a data-icon="tag"/>').appendTo($li).text(response.tags[i].title).data('id', response.tags[i].id);
$li = $('<li/>')
.appendTo($ul)
.addClass(response.tags[i].exclude ? 'disabled' : '');

$('<a data-icon="tag"/>')
.appendTo($li)
.text(response.tags[i].title)
.data('id', response.tags[i].id)
.addClass(response.tags[i].exclude ? 'disabled' : '');
}

if (!response.exactMatch) {
$li = $('<li/>').appendTo($ul);
$('<a data-icon="plus"/>').appendTo($li).text(data.search);
}

$ul.find('> li:first-child > a').addClass('hover');
$ul.find('> li:not(.disabled):first > a').addClass('hover');

this.searchMenu = new Garnish.Menu($menu, {
attachToElement: this.$addTagInput,
Expand All @@ -164,9 +171,14 @@ Craft.TagSelectInput = Craft.BaseElementSelectInput.extend(
},

selectTag: function(option) {
var $option = $(option),
id = $option.data('id'),
title = $option.text();
var $option = $(option);

if ($option.hasClass('disabled')) {
return;
}

var id = $option.data('id');
var title = $option.text();

var $element = $('<div/>', {
'class': 'element small removable',
Expand Down

0 comments on commit 0a23f29

Please sign in to comment.