Skip to content

Commit 1af2d3f

Browse files
Tidy up hidden inputs and error handling
1 parent f1c33c1 commit 1af2d3f

2 files changed

Lines changed: 23 additions & 23 deletions

File tree

src/review-form.ts

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ export class ReviewForm extends LitElement {
6565
return html`<form
6666
id="review-form"
6767
action="${this.baseHost}${this.endpointPath}"
68+
method="post"
6869
>
69-
${this.errors
70+
${this.errors.length
7071
? html`<div class="errors">${this.errors.join(' ')}</div>`
7172
: nothing}
7273
${this.starsInputTemplate} ${this.subjectInputTemplate}
@@ -135,27 +136,24 @@ export class ReviewForm extends LitElement {
135136

136137
/* Renders all the hidden inputs we use to store other information for form submission */
137138
private get hiddenInputsTemplate(): HTMLTemplateResult {
138-
return html`${this.identifier
139-
? html`<input
140-
type="hidden"
141-
name="identifier"
142-
.value=${this.identifier}
143-
/>`
144-
: nothing}
145-
${this.token
146-
? html`<input
147-
type="hidden"
148-
name="field_reviewtoken"
149-
.value=${this.token}
150-
/>`
151-
: nothing}
152-
${this.recaptchaToken
153-
? html`<input
154-
type="hidden"
155-
name="g-recaptcha-response"
156-
.value=${this.recaptchaToken}
157-
/>`
158-
: nothing}`;
139+
return html`<input
140+
type="hidden"
141+
name="field_reviewtoken"
142+
.value=${this.token}
143+
/>
144+
<input
145+
type="hidden"
146+
name="g-recaptcha-response"
147+
.value=${this.recaptchaToken}
148+
/>
149+
<input type="hidden" name="action" value="1" />
150+
${this.identifier
151+
? html`<input
152+
type="hidden"
153+
name="identifier"
154+
.value=${this.identifier}
155+
/>`
156+
: nothing}`;
159157
}
160158

161159
private get actionButtonsTemplate(): HTMLTemplateResult {
@@ -199,11 +197,13 @@ export class ReviewForm extends LitElement {
199197

200198
private async handleSubmit(e: Event): Promise<void> {
201199
e.preventDefault();
200+
if (!this.reviewForm.reportValidity()) return;
202201

203202
try {
204203
const recaptchaToken = await this.recaptchaWidget?.execute();
205204
this.recaptchaToken = recaptchaToken ?? '';
206205

206+
// Wait for recaptcha token to be added to form
207207
await this.updateComplete;
208208
this.reviewForm.requestSubmit();
209209
} catch {

test/review-form.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ describe('ReviewForm', () => {
9999
);
100100

101101
const errors = el.shadowRoot?.querySelector('.errors') as HTMLDivElement;
102-
expect(errors).not.to.exist;
102+
expect(errors).to.be.null;
103103
});
104104

105105
it('prefills the old review body if provided', async () => {

0 commit comments

Comments
 (0)