Skip to content

Commit

Permalink
Use type definition for the controller's element.
Browse files Browse the repository at this point in the history
  • Loading branch information
dombesz committed Jan 15, 2025
1 parent 6932aaf commit c7fa8b3
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions frontend/src/stimulus/controllers/form-preview.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,19 @@
* ++
*/

import { ApplicationController } from 'stimulus-use';
import { Controller } from '@hotwired/stimulus';

export default class FormPreviewController extends ApplicationController {
export default class FormPreviewController extends Controller<HTMLFormElement> {
static values = { url: String };

declare readonly formTarget:HTMLFormElement;
declare urlValue:string;

connect() {
// Ensure this.element is a form element
if (!(this.element instanceof HTMLFormElement)) {
throw new Error('The controller must be bound to a <form> element');
}
}

async submit():Promise<void> {
if (!this.urlValue) {
return;
}

const form = this.element as HTMLFormElement;
const form = this.element;
form.action = this.urlValue;

form.requestSubmit();
Expand Down

0 comments on commit c7fa8b3

Please sign in to comment.