Skip to content
This repository has been archived by the owner on Dec 3, 2021. It is now read-only.
/ turbo-form Public archive

Library to augment forms using @hotwired/turbo.

License

Notifications You must be signed in to change notification settings

alvincrespo/turbo-form

Repository files navigation

⚠️⚠️⚠️ Archived. Turbo has since implemented data-turbo-confirm and data-turbo-method. ⚠️⚠️⚠️

CircleCI

Turbo Form

This library helps port some functionality from rails-ujs to Turbo.

If you've ever used link_to with remote: true and are thinking about using Turbo as a replacement to UJS - you'll need to do some extra work. However, Turbo give us everything we need to port over this functionality.

Thus, this library.

With this library, you just need to make some slight changes. For example,

Before

<%= link_to "Delete article", @article, remote: true, method: :delete %>

After

<%= link_to "Delete article", @article, data: { controller: "link-method", method: "delete" } %>

The idea is to continue moving forward with Turbo with minimal changes to existing app code.

Installation

yarn add @foxglovetech/turbo-form

Usage

Setup

The first you'll want to do is register the controllers:

import {
  ConfirmController,
  LinkMethodController,
} from "@foxglovetech/turbo-form";

const application = Application.start();
application.register("confirm", ConfirmController);
application.register("link-method", LinkMethodController);

ConfirmController

If you're looking for a confirmation dialog:

<%= button_to "Delete This", some_path(resource_name), data: { controller: "confirm", confirm_message: "Are you sure?" }, method: :delete %>

LinkMethodController

If you need a link to make a request:

<%= link_to "Duplicate", some_path(resource_name), data: { controller: "link-method", method: "post" } %>

Development

Checkout the CONTRIBUTING for info on how to help out with contributions/development.

License

This project is licensed under the MIT License