Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tags select clear button #1463

Merged
merged 6 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/assets/javascripts/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ $(() => {
draftTimeout = setTimeout(() => {
const { draft, field } = parseDraft(ev.target);
saveDraft(draft, field);
}, 3000);
}, 1000);
});

postFields.on('paste', async (evt) => {
Expand Down
11 changes: 6 additions & 5 deletions app/assets/javascripts/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ $(() => {
return $(tagSpan + descSpan);
}

$('.js-tag-select').each((i, el) => {
$('.js-tag-select').each((_i, el) => {
const $tgt = $(el);
let $this;
const useIds = $tgt.attr('data-use-ids') === 'true';
Expand All @@ -46,7 +46,7 @@ $(() => {
},
headers: { 'Accept': 'application/json' },
delay: 100,
processResults: data => {
processResults: (data) => {
// (for the tour)
if (Number($this.data('tag-set')) === -1) {
return {
Expand All @@ -68,6 +68,7 @@ $(() => {
};
},
},
placeholder: '',
templateResult: template,
allowClear: true
});
Expand All @@ -90,7 +91,7 @@ $(() => {
return synonymsString;
}

$('#add-tag-synonym').on('click', ev => {
$('#add-tag-synonym').on('click', (ev) => {
const $wrapper = $('#tag-synonyms-wrapper');
const lastId = $wrapper.children('.tag-synonym').last().attr('data-id');
const newId = parseInt(lastId, 10) + 1;
Expand Down Expand Up @@ -120,7 +121,7 @@ $(() => {
synonym.hide();
}

$('.js-add-required-tag').on('click', ev => {
$('.js-add-required-tag').on('click', (ev) => {
const $tgt = $(ev.target);
const useIds = $tgt.attr('data-use-ids') === 'true';
const tagId = $tgt.attr('data-tag-id');
Expand All @@ -136,7 +137,7 @@ $(() => {
}
});

$('.js-rename-tag').on('click', async ev => {
$('.js-rename-tag').on('click', async (ev) => {
const $tgt = $(ev.target).is('a') ? $(ev.target) : $(ev.target).parents('a');
const categoryId = $tgt.attr('data-category');
const tagId = $tgt.attr('data-tag');
Expand Down
8 changes: 6 additions & 2 deletions app/controllers/posts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -602,8 +602,12 @@ def save_draft
key_name = [:body, :saved_at].include?(key) ? base_key : "#{base_key}.#{key}"

if key == :tags
if params[key].present?
RequestContext.redis.sadd(key_name, params[key])
valid_tags = params[key]&.select(&:present?)

RequestContext.redis.del(key_name)

if valid_tags.present?
RequestContext.redis.sadd(key_name, valid_tags)
end
else
RequestContext.redis.set(key_name, params[key])
Expand Down
6 changes: 3 additions & 3 deletions app/views/categories/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@
<% disabled = @category.tag_set.nil? %>
<%= f.select :required_tag_ids, options_for_select(@category.required_tags.map { |t| [t.name, t.id] },
selected: @category.required_tag_ids),
{ include_blank: true }, multiple: true, class: 'form-element js-tag-select js-required-tags',
{}, multiple: true, class: 'form-element js-tag-select js-required-tags',
data: { tag_set: @category.tag_set&.id, create: 'false', use_ids: 'true' }, disabled: disabled %>
</div>

Expand All @@ -239,7 +239,7 @@

<%= f.select :topic_tag_ids, options_for_select(@category.topic_tags.map { |t| [t.name, t.id] },
selected: @category.topic_tag_ids),
{ include_blank: true }, multiple: true, class: 'form-element js-tag-select js-topic-tags',
{}, multiple: true, class: 'form-element js-tag-select js-topic-tags',
data: { tag_set: @category.tag_set&.id, create: 'false', use_ids: 'true' }, disabled: disabled %>
</div>

Expand All @@ -256,7 +256,7 @@

<%= f.select :moderator_tag_ids, options_for_select(@category.moderator_tags.map { |t| [t.name, t.id] },
selected: @category.moderator_tag_ids),
{ include_blank: true }, multiple: true, class: 'form-element js-tag-select js-moderator-tags',
{}, multiple: true, class: 'form-element js-tag-select js-moderator-tags',
data: { tag_set: @category.tag_set&.id, create: 'false', use_ids: 'true' }, disabled: disabled %>
</div>
</details>
Expand Down
2 changes: 1 addition & 1 deletion app/views/posts/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
<%= f.select :tags_cache, options_for_select(
(tags || post.tags_cache).map { |t| [t, t] },
selected: tags || post.tags_cache),
{ include_blank: true },
{},
multiple: true,
class: "form-element js-tag-select",
data: { tag_set: category.tag_set_id } %>
Expand Down
8 changes: 7 additions & 1 deletion app/views/tour/question2.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@

<div class="form-group">
<label class="form-element" for="post_tags_cache">Tags (at least one):</label>
<input name="post[tags_cache][]" type="hidden" value="" /><select multiple="multiple" class="form-element js-tag-select" data-tag-set="<%= @tagset_id %>" name="post[tags_cache][]" id="post_tags_cache"><option value=""></option></select>
<input name="post[tags_cache][]" type="hidden" value="" />
<select multiple="multiple"
class="form-element js-tag-select"
data-tag-set="<%= @tagset_id %>"
name="post[tags_cache][]"
id="post_tags_cache">
</select>
</div>

</div>
Expand Down
Loading