Talks
Speakers
Events
Topics
Search
Sign in
Search
Home
Talks
Speakers
Events
Topics
Leaderboard
Use
Analytics
Sign in
search talks for
⏎
Suggest modification to this talk
Title
Description
Working with forms is pretty common in web apps, but this time my team was requested to give support for dynamic forms created by admins in an admin panel and used in several places (real story). There are many ways to implement it, but our goal was to build it in a way that felt natural in Rails. This talk is for you if you’d like to learn how we used the ActiveModel's API together with the Form Objects pattern to support our dynamic forms feature, and the cherry on top is the usage of Hotwire to accomplish some more advanced features. And all of this is done without a single line of JS :)
Date
Summarized using AI?
If this talk's summary was generated by AI, please check this box. A "Summarized using AI" badge will be displayed in the summary tab to indicate that the summary was generated using AI.
Show "Summarized using AI" badge on summary page
Summary
Markdown supported
In this video titled "All you need to know to build Dynamic Forms (JS FREE)", Santiago Bartesaghi presents a thorough guide on implementing dynamic forms within Ruby on Rails applications. Presented during RailsConf 2021, the talk outlines the process of creating forms that can be configured in the database by admins without the need for deployments, thereby enhancing the flexibility and usability of web applications. ### Key Points Discussed: - **Definition of Dynamic Forms**: Dynamic forms are configurable by admins through a user interface and can reflect changes in the application immediately. They can include multiple steps and types of fields, such as text inputs, dropdowns, and radio buttons. - **ActiveModel and Form Objects**: The implementation focuses on leveraging the ActiveModel API along with the Form Objects pattern to manage dynamic forms efficiently. Bartesaghi introduced a simple gem for form objects called "yes" to facilitate this process. - **Database Configuration**: The discussion includes how to set up a relational database model called `form_config`, which captures the dynamic attributes of forms such as names, labels, types, and validations. - **Rendering the Form**: Bartesaghi elaborates on rendering dynamic forms using code that closely resembles standard Rails forms. He emphasizes the use of a loop to iterate over field configurations, allowing for dynamic rendering of fields. - **Handling Submissions and Validations**: The video covers how to handle form submissions, execute validations, and manage form persistence with a custom save method that is intuitive like ActiveRecord’s save method. - **Repeatable Fields Feature**: The complexities of implementing repeatable fields are explained as a significant challenge. Bartesaghi introduces Turbo streams as part of Hotwire, allowing developers to create dynamic interfaces with minimal JavaScript. Instead of extensive client-side JavaScript, forms can now leverage Turbo for seamless server-side updates. ### Significant Examples and Case Studies: - The talk utilizes a real-world example from a project for universities that required customizable forms for online courses, showcasing actual database records used in dynamic form creation. - A demonstration of the repeatable fields feature illustrates how Turbo streams can be integrated to manage user interactions and DOM updates directly from server responses. ### Conclusions and Takeaways: - The implementation discussed provides a Ruby-friendly approach to deploying dynamic forms, significant for developers who prefer to work in Ruby over JavaScript. - Bartesaghi encourages developers to explore Rails' powerful tools, including ActiveModel, Singleton classes, and Hotwire, to enhance their applications. - He emphasizes the scalability and reusability of the solution across different projects and configurations, asserting that these concepts can serve as valuable additions to developers' skill sets.
Suggest modifications
Cancel