Bug 26355: (follow-up) Allow the 'Clear' button to remove empty messages

Signed-off-by: Christopher Brannon <cbrannon@cdalibrary.org>
Signed-off-by: Andrew Fuerste Henry <andrew@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Matt Blenkinsop 2026-03-04 09:19:14 +00:00 committed by Lucas Gass
parent cb9e70f8c2
commit 029a4f71ec
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
1 changed files with 17 additions and 6 deletions

View File

@ -562,7 +562,7 @@
[% ELSE %]
<textarea type="text" name="self_renewal_information_message" id="self_renewal_information_message_[% loop.index | html %]" cols="40" rows="4"></textarea>
[% END %]
<a href="#" class="clear_message"><i class="fa fa-fw fa-trash-can"></i> Clear</a>
<a href="#" class="clear_message" data-clear-target="[% loop.index | html %]"><i class="fa fa-fw fa-trash-can"></i> Clear</a>
<a href="#" class="clone_message"><i class="fa fa-fw fa-plus"></i> New</a>
</li>
[% END %]
@ -931,14 +931,19 @@
<script nonce="[% Koha.CSPNonce | $raw %]">
var table_settings = [% TablesSettings.GetTableSettings( 'admin', 'categories', 'patron_categories', 'json' ) | $raw %];
$(document).ready(function () {
function getTextareaFromParent(el) {
return $(el).children("textarea").eq(0);
};
$("#category_form").on(
"click",
".clone_message",
function (e) {
e.preventDefault();
var original = $(this).parent();
var clone = $(this).parent().clone();
$(clone).children("div.hint").remove()
const original = $(this).parent();
const indexToIncrement = parseInt(getTextareaFromParent(original).prop("id").match(/\d+/g));
const clone = $(this).parent().clone();
$(clone).children("div.hint").remove();
getTextareaFromParent(clone).prop("id", "self_renewal_information_message_" + (indexToIncrement + 1));
$(original).after(clone);
return false;
}
@ -948,8 +953,14 @@
".clear_message",
function (e) {
e.preventDefault();
var original = $(this).parent();
$("input", original).val("");
const messageCount = $("textarea[name=self_renewal_information_message]").length
if(messageCount === 1) {
const original = $(this).parent();
$("textarea", original).val("");
} else {
const original = $(this).parent();
$(original).remove();
}
}
);
});