Conquering Forms in Vue

Rate this content
Bookmark

Web forms are the connective tissue of the internet. Without them, people cannot request their health records, apply for university, order pad thai, or book a plane ticket. Yet too often, the tools we use to build those forms are a grab bag of libraries and DIY solutions that can result in a subpar user experience, poor accessibility, and low maintainability.

In this talk, we will introduce FormKit — a form-building framework — and explore how this tool can empower Vue developers to write consistent, accessible, even delightful forms without spending a lifetime building them.

Talk table of contents:

  • - The problem with forms, why they’re hard
  • - Introduction to FormKit
  • - Input library
  • - Validation
  • - Accessibility
  • - Form architecture
  • - Generating forms from JSON
  • - Next steps and closing statements

This talk has been presented at Vue.js London 2023, check out the latest edition of this Tech Conference.

FAQ

FormKit is a form building framework designed specifically for Vue, focusing on the architecture of your form rather than just being a component library. It automates the collection of input values, applies validation with a single property, and allows for easy form generation. This framework significantly reduces the complexity and boilerplate code associated with form handling in Vue.

FormKit automatically collects input values, eliminating the need for manual setup of v-model for each input. It also simplifies validation by allowing developers to apply rules directly through a single prop on the input. FormKit ships with numerous predefined validation rules that include internationalization support.

The single component approach in FormKit standardizes form inputs across applications, making learning and integration easier. Every native HTML input type is mirrored in FormKit with added functionalities, creating a consistent API and reducing inconsistencies found in standard HTML forms.

Yes, FormKit supports the structuring of nested and grouped data within forms. This feature allows developers to encapsulate specific parts of forms, such as addresses, into separate components or groups, maintaining a clean and organized data structure even in complex form setups.

FormKit Schema is a JSON serializable data format that allows for defining and generating forms and their structures. It supports rendering DOM elements and Vue components, and includes advanced features like conditional rendering and expressions. Schema can dynamically generate forms based on stored or transmitted data configurations, enhancing flexibility and reusability.

FormKit enhances form accessibility by automatically generating IDs and linking labels and descriptions correctly, adhering to accessibility standards. It also handles error messages effectively by placing them next to the relevant input fields, as recommended by usability studies, thus making forms more user-friendly.

Learning resources for FormKit can be found on the official website, FormKit.com, and through Vue School's series of courses available at viewschool.io. These resources provide detailed guidance on utilizing FormKit effectively in your Vue applications.

Justin Schroeder
Justin Schroeder
24 min
15 May, 2023

Comments

Sign in or register to post your comment.

Video Summary and Transcription

Today's Talk focused on building forms in Vue using FormKit. The speaker highlighted the simplicity of forms in Vue and the importance of adding buttons, labels, and help text for a better user experience. They also discussed handling form data and errors, refactoring form components, and implementing inline validation. The introduction to FormKit showcased its features such as a single component approach, automatic data collection, and simplified form building. The talk also covered applying validation and form generation using the FormKit schema, which allows for easy form representation and rendering.
Available in Español: Dominando los Formularios en Vue

1. Introduction to Conquering Forms in Vue

Short description:

Hi Vue.js Live. Today we'll learn about making forms in Vue with a focus on FormKit. I'm Justin Schrader, involved in projects like FormKit, Arrow.js, AutoAnimate, and Vue Formulate. Building complex forms can be tedious and hard to maintain. However, forms are easy. All you need is a form tag and a couple of input tags.

Hi Vue.js Live. I'm talking to you today about conquering forms in Vue. We're going to learn about how easy and wonderful it is to make forms in Vue with a particular bent on FormKit.

So I'm Justin Schrader and you might know me from the internet, you might not. Some of the open source projects that I'm involved in are FormKit, which is what we're talking about today. Arrow.js, which is a small two kilobyte lightweight alternative to things like React and Vue. Another one is AutoAnimate, which is really neat. Works great with Vue and React and really any other ones. And it lets you automatically animate DOM elements coming in and out of the DOM or moving around. And then Vue Formulate, which is the spiritual ancestor of FormKit. It was a Vue 2 library, all about building forms in Vue. And finally, I'm a partner in an agency called Braid here in Charlottesville, Virginia. So that's me.

This is also me in 2019 staring at a massive client project that we had built with hundreds, maybe even thousands of inputs and forms. It was incredibly tedious to build, very hard to maintain. And at the time we were thinking there's just gotta be a better way. So let's talk a little bit about that because the prevailing wisdom on the internet right now, especially in dev Twitter is forms are not hard. Forms are easy. In fact, Ryan Florence, one of the creators of Remix recently had this tweet and I think it applies, you know, he's talking about remix and react, but I think it applies to really any of the big libraries out there. Let me read this. I don't think there should even be form abstractions. Forms are fundamentally markup user interactions, event handlers, state management requests between views fell to react. What will the form library out here? Toss in some validation and be done with it. Interesting sentiment. And you know what? Fundamentally Ryan's right. Forms are easy. All you really need is a form tag and a couple of input tags and voila, you've got yourself a completely valid form. Um, here's one. It's a username and password. This could be a login or registration.

2. Adding Buttons, Labels, and Help Text

Short description:

It's incredibly simple. We should put a button for submitting the form. We need labels for accessibility. Adding help text makes the form look better. Now we're ready to accept and process the data.

And as you can see, it's incredibly simple. Now to be fair, we probably should put a button in there for submitting the form. Um, in this case we put a register button in there. So this must be a registration form.

And realistically for accessibility reasons, we're going to need some labels on those. Plus people won't even know what to fill out if we don't put them on there. So let's go ahead and do that. We'll just add an ID to our inputs because we need to semantically link them with the four attributes. So we'll just pop that on there. Great. Look at our form renders. People would know how to fill this out. We are good to go.

Although to be fair, it does look a little bit like a login form, so we should probably add some help text on those inputs. And to do that, all we got to do is add an ARIA described by on our actual input. And then wherever we put our help text, we can put an ID, uh, something like, you know, username help. And now we're good. Now we're off to the races. Here we go. Now our form is starting to look better. We've got help text, you know, could probably use some styles, but it's, but it's looking good. Forms are easy.

To be fair, this doesn't actually do anything yet. So let's go ahead and put a script set up in the head here, and we'll just put an at submit. This is view. Super easy. Submit handler. And now we're ready to actually accept this data and do something with it. And there's a couple ways. We can get the data right.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

Building Better Websites with Remix
React Summit Remote Edition 2021React Summit Remote Edition 2021
33 min
Building Better Websites with Remix
Top Content
Remix is a web framework built on React Router that focuses on web fundamentals, accessibility, performance, and flexibility. It delivers real HTML and SEO benefits, and allows for automatic updating of meta tags and styles. It provides features like login functionality, session management, and error handling. Remix is a server-rendered framework that can enhance sites with JavaScript but doesn't require it for basic functionality. It aims to create quality HTML-driven documents and is flexible for use with different web technologies and stacks.
Speeding Up Your React App With Less JavaScript
React Summit 2023React Summit 2023
32 min
Speeding Up Your React App With Less JavaScript
Top Content
Watch video: Speeding Up Your React App With Less JavaScript
Mishko, the creator of Angular and AngularJS, discusses the challenges of website performance and JavaScript hydration. He explains the differences between client-side and server-side rendering and introduces Quik as a solution for efficient component hydration. Mishko demonstrates examples of state management and intercommunication using Quik. He highlights the performance benefits of using Quik with React and emphasizes the importance of reducing JavaScript size for better performance. Finally, he mentions the use of QUIC in both MPA and SPA applications for improved startup performance.
Full Stack Documentation
JSNation 2022JSNation 2022
28 min
Full Stack Documentation
Top Content
The Talk discusses the shift to full-stack frameworks and the challenges of full-stack documentation. It highlights the power of interactive tutorials and the importance of user testing in software development. The Talk also introduces learn.svelte.dev, a platform for learning full-stack tools, and discusses the roadmap for SvelteKit and its documentation.
SolidJS: Why All the Suspense?
JSNation 2023JSNation 2023
28 min
SolidJS: Why All the Suspense?
Top Content
Suspense is a mechanism for orchestrating asynchronous state changes in JavaScript frameworks. It ensures async consistency in UIs and helps avoid trust erosion and inconsistencies. Suspense boundaries are used to hoist data fetching and create consistency zones based on the user interface. They can handle loading states of multiple resources and control state loading in applications. Suspense can be used for transitions, providing a smoother user experience and allowing prioritization of important content.
From GraphQL Zero to GraphQL Hero with RedwoodJS
GraphQL Galaxy 2021GraphQL Galaxy 2021
32 min
From GraphQL Zero to GraphQL Hero with RedwoodJS
Top Content
Tom Pressenwurter introduces Redwood.js, a full stack app framework for building GraphQL APIs easily and maintainably. He demonstrates a Redwood.js application with a React-based front end and a Node.js API. Redwood.js offers a simplified folder structure and schema for organizing the application. It provides easy data manipulation and CRUD operations through GraphQL functions. Redwood.js allows for easy implementation of new queries and directives, including authentication and limiting access to data. It is a stable and production-ready framework that integrates well with other front-end technologies.
RedwoodJS: The Full-Stack React App Framework of Your Dreams
React Summit Remote Edition 2021React Summit Remote Edition 2021
43 min
RedwoodJS: The Full-Stack React App Framework of Your Dreams
Top Content
Redwood JS is a full stack React app framework that simplifies development and testing. It uses a directory structure to organize code and provides easy data fetching with cells. Redwood eliminates boilerplate and integrates Jest and Storybook. It supports pre-rendering and provides solutions for authentication and deployment. Redwood is a cross-client framework that allows for building web and mobile applications without duplicating work.

Workshops on related topic

Building WebApps That Light Up the Internet with QwikCity
JSNation 2023JSNation 2023
170 min
Building WebApps That Light Up the Internet with QwikCity
Featured WorkshopFree
Miško Hevery
Miško Hevery
Building instant-on web applications at scale have been elusive. Real-world sites need tracking, analytics, and complex user interfaces and interactions. We always start with the best intentions but end up with a less-than-ideal site.
QwikCity is a new meta-framework that allows you to build large-scale applications with constant startup-up performance. We will look at how to build a QwikCity application and what makes it unique. The workshop will show you how to set up a QwikCitp project. How routing works with layout. The demo application will fetch data and present it to the user in an editable form. And finally, how one can use authentication. All of the basic parts for any large-scale applications.
Along the way, we will also look at what makes Qwik unique, and how resumability enables constant startup performance no matter the application complexity.
Back to the Roots With Remix
React Summit 2023React Summit 2023
106 min
Back to the Roots With Remix
Featured Workshop
Alex Korzhikov
Pavlik Kiselev
2 authors
The modern web would be different without rich client-side applications supported by powerful frameworks: React, Angular, Vue, Lit, and many others. These frameworks rely on client-side JavaScript, which is their core. However, there are other approaches to rendering. One of them (quite old, by the way) is server-side rendering entirely without JavaScript. Let's find out if this is a good idea and how Remix can help us with it?
Prerequisites- Good understanding of JavaScript or TypeScript- It would help to have experience with React, Redux, Node.js and writing FrontEnd and BackEnd applications- Preinstall Node.js, npm- We prefer to use VSCode, but also cloud IDEs such as codesandbox (other IDEs are also ok)
Web Accessibility for Ninjas: A Practical Approach for Creating Accessible Web Applications
React Summit 2023React Summit 2023
109 min
Web Accessibility for Ninjas: A Practical Approach for Creating Accessible Web Applications
Workshop
Asaf Shochet Avida
Eitan Noy
2 authors
In this hands-on workshop, we’ll equip you with the tools and techniques you need to create accessible web applications. We’ll explore the principles of inclusive design and learn how to test our websites using assistive technology to ensure that they work for everyone.
We’ll cover topics such as semantic markup, ARIA roles, accessible forms, and navigation, and then dive into coding exercises where you’ll get to apply what you’ve learned. We’ll use automated testing tools to validate our work and ensure that we meet accessibility standards.
By the end of this workshop, you’ll be equipped with the knowledge and skills to create accessible websites that work for everyone, and you’ll have hands-on experience using the latest techniques and tools for inclusive design and testing. Join us for this awesome coding workshop and become a ninja in web accessibility and inclusive design!
Automated accessibility testing with jest-axe and Lighthouse CI
TestJS Summit 2021TestJS Summit 2021
85 min
Automated accessibility testing with jest-axe and Lighthouse CI
Workshop
Bonnie Schulkin
Bonnie Schulkin
Do your automated tests include a11y checks? This workshop will cover how to get started with jest-axe to detect code-based accessibility violations, and Lighthouse CI to validate the accessibility of fully rendered pages. No amount of automated tests can replace manual accessibility testing, but these checks will make sure that your manual testers aren't doing more work than they need to.
Web Accessibility in JavaScript Apps
React Summit 2022React Summit 2022
161 min
Web Accessibility in JavaScript Apps
Workshop
Sandrina Pereira
Sandrina Pereira
Often we see JavaScript damaging the accessibility of a website. In this workshop, you’ll learn how to avoid common mistakes and how to use JS in your favor to actually enhance the accessibility of your web apps!
In this workshop we’ll explore multiple real-world examples with accessibility no-nos, and you'll learn how to make them work for people using a mouse or a keyboard. You’ll also learn how screen readers are used, and I'll show you that there's no reason to be afraid of using one!
Join me and let me show you how accessibility doesn't limit your solutions or skills. On the contrary, it will make them more inclusive!
By the end, you will:- Understand WCAG principles and how they're organized- Know common cases where JavaScript is essential to accessibility- Create inclusive links, buttons and toggleble elements- Use live regions for errors and loading states- Integrate accessibility into your team workflow right away- Realize that creating accessible websites isn’t as hard as it sounds ;)
Let AI Be Your Docs
JSNation 2024JSNation 2024
69 min
Let AI Be Your Docs
Workshop
Jesse Hall
Jesse Hall
Join our dynamic workshop to craft an AI-powered documentation portal. Learn to integrate OpenAI's ChatGPT with Next.js 14, Tailwind CSS, and cutting-edge tech to deliver instant code solutions and summaries. This hands-on session will equip you with the knowledge to revolutionize how users interact with documentation, turning tedious searches into efficient, intelligent discovery.
Key Takeaways:
- Practical experience in creating an AI-driven documentation site.- Understanding the integration of AI into user experiences.- Hands-on skills with the latest web development technologies.- Strategies for deploying and maintaining intelligent documentation resources.
Table of contents:- Introduction to AI in Documentation- Setting Up the Environment- Building the Documentation Structure- Integrating ChatGPT for Interactive Docs