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:
parent
cb9e70f8c2
commit
029a4f71ec
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue