fix: turbo_input js controller can accept a method in option

This commit is contained in:
simon lehericey 2024-12-09 11:24:34 +01:00
parent 7d48c294d6
commit 84f301cdb8
No known key found for this signature in database
GPG key ID: CDE670D827C7B3C5

View file

@ -5,10 +5,12 @@ import { ApplicationController } from './application_controller';
export class TurboInputController extends ApplicationController { export class TurboInputController extends ApplicationController {
static values = { static values = {
url: String, url: String,
method: { type: String, default: 'get' },
loadOnConnect: { type: Boolean, default: false } loadOnConnect: { type: Boolean, default: false }
}; };
declare readonly urlValue: string; declare readonly urlValue: string;
declare readonly methodValue: string;
declare readonly loadOnConnectValue: boolean; declare readonly loadOnConnectValue: boolean;
connect(): void { connect(): void {
@ -22,6 +24,8 @@ export class TurboInputController extends ApplicationController {
const target = this.element as HTMLInputElement; const target = this.element as HTMLInputElement;
const url = new URL(this.urlValue, document.baseURI); const url = new URL(this.urlValue, document.baseURI);
url.searchParams.append(target.name, target.value); url.searchParams.append(target.name, target.value);
httpRequest(url.toString()).turbo(); httpRequest(url.toString(), {
method: this.methodValue
}).turbo();
} }
} }