fix: checklist required mechanism
This commit is contained in:
parent
635c2a2c15
commit
583e5d6beb
|
|
@ -5,11 +5,14 @@
|
||||||
<title>Lishwist</title>
|
<title>Lishwist</title>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<script>
|
<script>
|
||||||
function someChecked(checkList) {
|
function getSubmissionNames(form) {
|
||||||
if (!checkList) {
|
return Array.from(new FormData(form).keys());
|
||||||
return
|
}
|
||||||
}
|
function acceptNames(form, submitId, ...acceptedNames) {
|
||||||
return Array.from(checkList).some(({checked}) => checked);
|
const submissionNames = getSubmissionNames(form);
|
||||||
|
const submitter = document.getElementById(submitId);
|
||||||
|
const accepted = submissionNames.length > 0 && submissionNames.every((name) => acceptedNames.includes(name));
|
||||||
|
submitter.disabled = !accepted;
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,9 @@
|
||||||
</nav>
|
</nav>
|
||||||
<h2>{{.Username}}'s list</h2>
|
<h2>{{.Username}}'s list</h2>
|
||||||
<form method="post" action="/{{.UserReference}}/update" autocomplete="off"
|
<form method="post" action="/{{.UserReference}}/update" autocomplete="off"
|
||||||
onchange="const checked = someChecked(this.unclaimed) || someChecked(this.claimed); this.mode[0].disabled = !checked; this.mode[1].disabled = !checked;">
|
onchange="acceptNames(this, 'claimSubmit', 'claimed', 'unclaimed'); acceptNames(this, 'completeSubmit', 'claimed');">
|
||||||
<button type="submit" name="mode" value="claim" disabled>Claim/Unclaim</button>
|
<button id="claimSubmit" type="submit" name="mode" value="claim" disabled>Claim/Unclaim</button>
|
||||||
<button type="submit" name="mode" value="complete" disabled>Complete</button>
|
<button id="completeSubmit" type="submit" name="mode" value="complete" disabled>Complete</button>
|
||||||
<ul>
|
<ul>
|
||||||
{{range .Gifts}}
|
{{range .Gifts}}
|
||||||
<li>
|
<li>
|
||||||
|
|
|
||||||
|
|
@ -11,9 +11,8 @@
|
||||||
</dd>
|
</dd>
|
||||||
</dl>
|
</dl>
|
||||||
<h2>Your list</h2>
|
<h2>Your list</h2>
|
||||||
<form method="post" action="/wishlist/delete" onchange="this.mode.disabled = !someChecked(this.gift)"
|
<form method="post" action="/wishlist/delete" onchange="acceptNames(this, 'deleteSubmit', 'gift')" autocomplete="off">
|
||||||
autocomplete="off">
|
<button id="deleteSubmit" type="submit" name="mode" value="delete" disabled>Delete</button>
|
||||||
<button type="submit" name="mode" value="delete" disabled>Delete</button>
|
|
||||||
<ul>
|
<ul>
|
||||||
{{range .Gifts}}
|
{{range .Gifts}}
|
||||||
<li>
|
<li>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue