When working on courses, I’m constantly fighting the battle between “just teach it how it is” and “this library could be updated to be better”. That happened this week in a big way with Superform, a form builder I built from scratch because all the other ones aren’t great.
Course content updates
The first three units of the Phlex on Rails course are complete!
Existing Rails apps
I’ve finished the existing Rails apps unit! Everything from installing Phlex in Rails to sending emails with Phlex components and ActionMailer.
Superform
Superform was long overdue for an upgrade. I built it for Phlex 1.x, but since then a lot has changed.
Here’s what it would look like rendering a Superform in 0.5.x
with Phlex 1.x
:
# No kits
render MyForm.new @user do |form|
render form.field(:name).input
render form.field(:email).input(type: :email)
end
In the 0.6.x
release of Superform I’m hoping to have something like Phlex::Kit
that makes rendering inputs more concise. Here’s where I’m at with that at the moment:
# Phlex::Kit and Field::Kit
MyForm @user do |form|
form.Field(:name).input
form.Field(:email).input(type: :email)
end
# Ruby 3.4 and all the kits
MyForm @user do
it.Field(:name)
it.Field(:email).input(type: :email)
end
# Pre-built form
class Form::User < Form::Base
def view_template
Field(:name).input
Field(:email).input(type: :email)
namespace(:address) do |a|
a.Field(:street).input
a.Field(:city).input
a.Field(:state).input
a.Field(:zip).input
end
end
end
# Render the pre-built form in Erb
<%= render Form::User.new @user %>
I’m calling these Superform::Field::Kit
. It’s kind of like Phlex::Kit
, but the way I chain the Phlex renderer to the component is a bit different.
What’s next?
The short answer, some research and Superform upgrades. I’m hoping to push Superform::Field::Kit
to 0.6.x
and start on the Build forms with components unit. If all goes well I’ll have that published next week.
I have a bit of research to do for the Phlex and Hotwire unit too because I want to make sure the built-in Rails Turbo helpers make sense with Phlex. If they don’t then I’ll probably add a Turbo library to the Superview library.