Skip to content

Commit

Permalink
refactor feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
russbiggs committed Oct 4, 2024
1 parent cb8e515 commit e211b9c
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/components/FeedbackForm.astro
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { Icon } from 'astro-icon/components';
<fieldset>
<legend>Was this page helpful?</legend>
<div class="feedback-form-buttons" style="margin-top: 0;">
<input type="hidden" name="feedback-value" id="feedback-value" value="" />
<button type="submit" data-value="good" style="margin-top: 0.5rem;">
<Icon name="mdi:emoticon-happy-outline" width="32" height="32" />
</button>
Expand All @@ -58,7 +59,7 @@ import { Icon } from 'astro-icon/components';

function onFormSubmit(e: SubmitEvent) {
e.preventDefault();
const value = e.submitter?.dataset.value;
const value = submitValueField.value;
trackEvent(`Feedback:${value}`);
const form = document.querySelector<HTMLFormElement>('.feedback-form');
(form!.firstElementChild! as HTMLFieldSetElement).disabled = true;
Expand All @@ -70,4 +71,12 @@ import { Icon } from 'astro-icon/components';

const form = document.querySelector<HTMLFormElement>('.feedback-form');
form!.addEventListener('submit', onFormSubmit);

const submitValueField = document.getElementById('feedback-value') as HTMLInputElement;

form!.querySelectorAll('button[type="submit"]').forEach(button => {
button.addEventListener('click', function(e) {
submitValueField!.value = (e.target as HTMLButtonElement).getAttribute('data-value')!;
});
});
</script>

0 comments on commit e211b9c

Please sign in to comment.