Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Building Forms with Vue.js

You're reading from   Building Forms with Vue.js Patterns for building and scaling complex forms with great UX

Arrow left icon
Product type Paperback
Published in Oct 2019
Publisher Packt
ISBN-13 9781839213335
Length 108 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Marina Mosti Hernandez Mosti Marina Mosti Hernandez Mosti
Author Profile Icon Marina Mosti Hernandez Mosti
Marina Mosti Hernandez Mosti
Arrow right icon
View More author details
Toc

Table of Contents (9) Chapters Close

Preface 1. Setting up the Demo Project FREE CHAPTER 2. A Form in its Simplest Form 3. Creating Reusable Form Components 4. Input Masks with v-mask 5. Input Validation with Vuelidate 6. Moving to a Global State with Vuex 7. Creating Schema-Driven Forms 8. Other Books You May Enjoy

Moving validation into our custom inputs

The amazing thing about having your own custom components is that you can craft them in any way you like. For this chapter, we're going to add support for both a valid and an invalid status to our components. The main validation logic will still be held by the parent, App.vue, as it is the containing component that holds our form.

Follow these steps to add validations:

  1. First, let's add new rules for each of our inputs. Add the following to the validations property:
validations: {
form: {
first_name: { alpha, required },
last_name: { alpha },
email: { email, required },
telephone: {
validPhone: phone => phone.match(/((\(\d{3}\) ?)|(\d{3}-))?
\d{3}-\d{4}/) !== null
},
website: { url },
love: { required }
}
},
  1. Don't forget to update your import statement to bring in the new validators that we are now...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image