Building the Next-Generation Data Lakehouse: 10X Performance

A data warehouse was defined by Bill Inmon as "a subject-oriented, integrated, nonvolatile, and time-variant collection of data in support of management's decisions" over 30 years ago. However, the initial data warehouses were unable to store massive heterogeneous data, hence the creation of data lakes. In modern times, data lakehouse emerges as a new paradigm. It is an open data management architecture featured by strong data analytics and governance capabilities, high flexibility, and open storage.

If I could only use one word to describe the next-gen data lakehouse, it would be unification:

Best Website Brokers and How to Choose the Right One

Best Website BrokersIf you're looking to buy or sell a website, you have two main options: (1) you can either do it yourself or (2) hire an expert to do all the work for you. Many online businesses choose the second option because they know the best website brokers will be able to not just get a better price for a site, but also take care of all the required documentation for a successful transfer. In this article, we will cover everything you need to know about finding and hiring the best website broker and getting them to help you in buying and selling websites.

The Power of Zero-Knowledge Proofs: Exploring the New ConsenSys zkEVM

It’s well-known that Ethereum needs support in order to scale. A variety of L2s (layer twos) have launched or are in development to improve Ethereum’s scalability. Among the most popular L2s are zero-knowledge-based rollups (also known as zk-rollups). Zk-rollups offer a solution that has both high scalability and minimal costs. In this article, we’ll define what zk-rollups are and review the latest in the market, the new ConsenSys zkEVM. 

This new zk-rollup—a fully EVM-equivalent L2 by ConsenSys— makes building with zero-knowledge proofs easier than ever. ConsenSys achieves this by allowing developers to port smart contracts easily, stay with the same toolset they already use, and bring users along with them smoothly—all while staying highly performant and cost-effective.

How to Easily Create a Restaurant Website with WordPress

Do you want to create a restaurant website with WordPress?

A restaurant website can help attract new customers and grow your business. It can also provide a better experience for your existing customers and keep them coming back to your restaurant, cafe, takeaway, or similar business.

In this article, we will show you how to create a restaurant website with WordPress.

How to easily create a restaurant website with WordPress

Why Create a Restaurant Website?

A website is one of the best ways to market your restaurant to new customers and provide a better experience for your existing clients.

By creating an online presence for your restaurant, you can introduce your business to people who are looking for venues and food just like yours.

An example of a restaurant website

After a potential customer discovers your business, a professionally-designed and helpful restaurant website will tell them everything they need to know about your business. They can then decide whether your restaurant is right for them.

Even if you have lots of loyal customers and a positive reputation in the local area, a restaurant website can help you improve the customer experience.

For example, it can allow customers to book a table online, send you questions using a convenient contact form, check out the latest menu, and much more.

An example of a restaurant online booking form

In this way, a restaurant website can keep your customers happy, so they carry on visiting you for months, or even years to come.

That said, let’s see how you can easily create a restaurant website with WordPress.

Which Is the Best Website Builder for Your Restaurant?

There are many website builders that can help you create a restaurant website but we recommend using WordPress.

According to our blogging research statistics, WordPress is the most popular website platform in the world. It powers nearly 43% of all websites on the internet including many top restaurant websites.

WordPress is also open-source and free. For more on this topic, see our article on why WordPress is free.

However, it’s important to realize that there are two types of WordPress software, so you don’t choose the wrong one.

First, there is WordPress.com, which is a blog hosting platform. Then, there is WordPress.org which is also known as self-hosted WordPress.

For a detailed comparison, you can see our guide on the difference between WordPress.com and WordPress.org.

For a restaurant website, we recommend using WordPress.org because it gives you complete ownership of your site and allows you to install third-party plugins, including plenty that are designed specifically for restaurant owners.

To learn more about why we recommend WordPress to all our readers, please see our complete WordPress review with pros and cons.

Step 1. Setting Up Your Restaurant Website

To create a WordPress website you’ll need a domain name and web hosting.

A domain name is your website’s address on the internet. This is what customers will type into their browsers to reach your website, such as justeat.com or tacobell.com.

Web hosting is where your website lives online. To help you out, we’ve hand-picked some of the best WordPress hosting that you can buy for a restaurant website.  

Although the WordPress software is free, hosting and domain names are where the costs can really start to add up.

A domain name typically costs $14.99/year and hosting costs start from $7.99/month. This is a lot for restaurants that already have bills and expenses to pay.

Thankfully, Bluehost has offers a free domain name, and our readers can get 60% off on web hosting. Bluehost is one of the largest hosting companies in the world, and an official WordPress-recommended hosting partner.

They’re also offering our readers a free SSL certificate. If you want to accept payments online, then an SSL certificate will help keep the customer’s credit and debit card information safe.

You can click the button below to get started for as little as $2.75 per month.

Once there, you will need to go to the Bluehost website in a new tab and click on the green ‘Get Started Now’ button.

Bluehost WordPress Hosting offer for WPBeginner Users

This will bring you to a pricing page where you can choose a hosting plan for your website.

We recommend choosing a Basic or Plus plan, as they’re the most popular web hosting plans among our readers.

Bluehost pricing plans

After selecting a plan, click on ‘Continue.’

On the next screen, you’ll need to choose a domain name.

Choosing a domain name for your restaurant website

Ideally, the domain name will be easy to pronounce and spell, easy to remember, and related to your business. The name of your restaurant is a great place to start, but sometimes that domain may already be taken by another business.

In that case, you can try extending the domain name by adding your restaurant’s location, your own name, or the type of food you serve.

Need help choosing a domain name for your restaurant website? See these tips and tools on how to choose the best domain name.

After choosing a name, click on the ‘Next’ button to continue.

Now you’ll need to provide your account information such as your name and email address. After that, you’ll also see optional extras that you can purchase.

We generally don’t recommend purchasing these extras straight away, as you can always add them later on if you need them.

Bluehost hosting package extras

After that, simply type in your payment information to complete the purchase.

Once you’ve done that, you’ll get an email with instructions on how to login to your web hosting control panel. This is your hosting account dashboard where you can manage your restaurant website, including setting up email notifications and asking for WordPress support.

It’s also where you’ll install the WordPress software.

Step 2. Create a New WordPress Website

When you signup with Bluehost using our link, Bluehost installs WordPress on your domain name automatically.

If you want to create a different WordPress website, then you can simply click on the ‘My Sites’ tab in the Bluehost dashboard.

Next, just click on the ‘Add Site’ button and select ‘Create New Site.’

Creating a new restaurant website using Bluehost

The Bluehost wizard will now guide you through the setup process.

First, you’ll need to type in a site title and optional tagline.

Adding a site title and tagline to your new restaurant website

Click on the ‘Next’ button to continue.

After that, Bluehost will ask you to select a domain name and path for your restaurant website. If you’ve already purchased a domain name, then you can simply select it from the dropdown menu.

Choosing a domain for your new WordPress website

If you don’t have a domain name then you can buy one by visiting the ‘Domains’ page inside the Bluehost dashboard.

After choosing a domain name, you can leave the directory path blank and let Bluehost fill it in for you. The installer will also show a few must-have WordPress plugins that you may want to install on your restaurant website including OptinMonster.

After that, click on the ‘Next’ button and the installer will set up your restaurant site.

Once it’s finished, you’ll see a ‘WordPress installed successfully’ message with information about your new website. You can now go ahead and click on the ‘Log into WordPress’ button.

This will take you to your site’s admin area.

Log into your new WordPress website dashboard

You can also log in to the WordPress dashboard by simply going to yoursite.com/wp-admin/ directly from your browser.

If you’re using a different WordPress website host such as SiteGroundHostingerHostGator, or WP Engine, then you can see our complete guide on how to install WordPress for all the top hosting providers.

Once WordPress is setup, you’re ready to start building a five-star restaurant website.

Step 3. Select a Restaurant Theme

WordPress themes are professionally designed templates that change how your restaurant site looks and acts.

By default, each WordPress site comes with a basic theme. If you visit your website, then it will look something like this:

The default WordPress theme

This is not very appealing for most customers, so you’ll usually want to replace the default WordPress theme.

There are lots of different premium and free WordPress business themes to choose from. You can generally categorize these as multipurpose WordPress themes, or niche industry themes.

Your typical restaurant website needs special features, like the ability to show a menu, photos, location information, business hours, and more.

With that in mind, it makes sense to look for a theme that’s designed for the food or hospitality industry. To help you out, we’ve collected the best WordPress restaurant themes.

You can also use a website and landing page builder plugin such as SeedProd.

The SeedProd page builder

SeedProd is the best drag and drop WordPress page builder and comes with built-in templates that you can use to build a professionally-designed restaurant website.

These templates include a menu, food photos, pricing, recipes, and more.

One of SeedProd's ready-made restaurant templates

Once you’ve chosen a restaurant theme, please see our step-by-step guide on how to install a WordPress theme.

After installing your theme, you may want to customize it by going to Appearance » Customize in the WordPress dashboard.

This will launch the theme customizer where you can fine-tune the theme settings and see your changes in the live preview.

The WordPress theme customizer

If you’re using one of the newer full site editing themes, then you’ll see the option for Appearance » Editor, which uses blocks similar to the content editor to customize your site.

Pro Tip: No matter what theme you’re using, neither the default WordPress customizer nor the full site editing offers a user-friendly drag and drop customization experience. For that reason, we recommend using a page builder like SeedProd to customize your theme.

Just remember that you can always return to this screen and continue customizing your theme. You can even completely change your WordPress theme at any point.

Step 4. Create a Custom Home Page

WordPress has two two default content types called posts and pages.

You’ll typically use posts to create articles and blogs. By default, the home page shows these posts in reverse chronological order, so the newest content appears at the top of the list.

A list of WordPress blog posts

You might use a blog to build a stronger relationship with their customers, improve your WordPress SEO, and get more traffic to your restaurant website. For example, you could write about recipes, share cooking tips, or blog about the latest restaurant industry news.

However, even if you plan to publish blog posts, you typically won’t show these on the home page. Instead, we recommend creating a custom home page that introduces your business to new visitors.

For step-by-step instructions on how to create an attention-grabbing restaurant home page, please see our guide on how to create a custom home page in WordPress.

Once you’re happy with the page’s design, it’s time to set it as your home page. To do this, go to Settings » Reading in the WordPress dashboard.

Adding a static home page to your WordPress website

Here, scroll to ‘Your homepage settings’ and select ‘A static page.’

Next, open the ‘Homepage’ dropdown and choose the page that you want to use.

Adding a static home page to your WordPress restaurant website

Then, simply scroll to the bottom of the screen and click on ‘Save Changes.’ Now, if you visit your website you’ll see the new home page in action.

If you are going to write blogs, then make sure you create a separate blog page to display your posts. If you don’t, then customers will struggle to find your latest WordPress blogs.

Step 5. Create an Online Restaurant Menu

Even long-term, loyal customers may want to look at your menu from time to time. By publishing your menu online, customers can look at it any time of day or night.

Publishing a menu can also help convince new customers to visit your restaurant.

It is possible to upload PDF files to your WordPress website. However, downloading a PDF menu can be difficult depending on the customer’s data plan and internet connection, and they’re non-responsive so they can be hard to read on some devices.

Plus, if you add new dishes or change your pricing, then you’ll also need to upload a completely new PDF.

For that reason, we recommend using SeedProd to add an online menu to your WordPress website. SeedProd also allows you to create a mobile responsive menu that looks great on every device.

One of SeedProd's professionally-designed restaurant templates

You can also easily update the menu as you add new dishes, change the prices, remove dishes, and more.

SeedProd even comes with a ‘Menu Sales Page’ template that’s perfect for creating a menu.

A restaurant menu, created using SeedProd

For detailed instructions, please see our guide on how to create an online restaurant menu.

Step 6. Set Up Online Food Ordering

Many restaurants allow customers to order food online. For example, you might give customers the option to pre-order their meal or place an order for delivery.

It may sound technical, but you can easily add online food ordering to your website using the WPForms plugin.

The WPForms form builder plugin for WordPress

WPForms is the best WordPress form builder that allows you to create online order forms for all kinds of products and services.

It even comes with a ready-made ‘Takeout Order Form’ that you can customize to suit your restaurant website.

Adding an online takeaway order form to your WordPress website

Every time someone completes the form, WPForms will notify you automatically so you can start working on that order straight away.

If you don’t want to accept cash on delivery, then WPForms supports all of the best payment gateways including PayPal and Stripe. This allows you to accept payments securely online, which is quick and convenient for your customers.

Accepting online payments for your restaurant website

For step-by-step instructions, please see our guide on how to set up food ordering for restaurants in WordPress.

Step 7. Add a Restaurant Booking Form

Today, most people expect to be able to book appointments through an automated system.

By adding a booking form to your restaurant website, you can accept reservations at any time of the day or night. You’ll never lose another customer just because you weren’t around to answer the phone. 

Booking forms can also automate a lot of the booking process. This includes collecting payments and emailing your customers to remind them about their upcoming booking.

You can easily add a restaurant booking form to your website using WPForms. This plugin has a ready-made dinner reservation form template that you can customize for your restaurant.

How to accept online bookings on a restaurant website

WPForms also integrates with all of the top email marketing providers. This makes it easy to send reservation confirmation emails to your customers.

As their booking approaches, you can even send the customer a reminder email, ask them to share any dietary requirements, send a pre-order form, and more.

Creating email notifications for your booking form

To learn more about adding a reservation form to your WordPress website, please see our guide on how to create a booking form in WordPress.

Step 8. Add a Contact Us Form

Even if you use a WordPress appointment and booking plugin, some customers may still need to talk to you directly.

While visitors could ring your phone number or send a message to your business email address, we always recommend adding a contact form to your website.

An example of a contact form

Most of the best contact form plugins come with built-in spam protection, so you won’t get any contact form spam. A form will also collect consistent information from visitors, so you’ll have all the data you need to write a helpful reply.

The easiest way to add a contact form to your WordPress website is by using the free WPForms plugin.

This free plugin comes with a built-in Simple Contact Form template that you can quickly customize using the drag and drop editor.

WPForms' contact form template

Then, simply add the form to any page, post, or widget-ready area using the ready-made WPForms block.

For detailed instructions, see our guide on how to create a contact form in WordPress.

Step 9. Add a Navigation Menu

Once you’ve added some content to your restaurant website, you’ll want to help visitors find their way around those pages and posts by adding a navigation menu.

An example of a restaurant menu, created using WordPress

No matter what theme you’re using, WordPress makes it really easy to add menus and sub-menus to your restaurant website.  

For a complete guide, please see our post on how to add a navigation menu.

The WordPress menu settings

Step 10. Add Social Proof to Your Restaurant Website

Social proof is one of the best ways to earn customer trust, and convince new people to visit your restaurant. After all, we’re more likely to try things that we see other people buying, using, or recommending.

People love sharing food photos on sites like Instagram and Facebook. With that in mind, we recommend adding social media feeds to your WordPress website.

Smash Balloon Instagram Feed is one of the best Instagram plugins for WordPress, and it allows you to easily show other people’s photos on your site.

Using this plugin, you can create a hashtag feed and show photos that customers have tagged your account in. This includes photos of your food, venue, and shots of customers having fun at your restaurant.

A food hashtag Instagram feed, created using Smash Balloon

For detailed step-by-step instructions, please see our guide on how to create a custom Instagram feed in WordPress.

If your customers regularly tweet about your restaurant, then Smash Balloon Twitter Feed also lets you create hashtag and mention feeds.

A Smash Balloon Twitter feed

For more instructions on adding a Twitter feed to WordPress, see our guide on how to embed tweets in WordPress.

Step 11. Show Customer Reviews

Customer reviews and testimonials can provide visitors with more information, and may even solve any question or worries customers have about visiting your restaurant.

If you already have a Facebook page, then it’s easy to display your Facebook reviews in WordPress using Smash Balloon Facebook Feed.

Facebook reviews, embedded in a WordPress website

If you want to show reviews from other platforms like Yelp or Google My Business, then there’s also plenty of customer review plugins for WordPress that you can use.

These plugins will collect reviews automatically and then organize them into a nice layout on your restaurant website.

Customer reviews embedded on a WordPress website

If you do add a customer review page in WordPress, then don’t forget to add it to your navigation menu too.

Don’t have any reviews to feature on your website? Then it’s time to start asking for them.

WPForms has a a ready-made Restaurant Review Form template that you can add to your website.

A restaurant review form, created using WPForms

Bonus Tips to Grow Your Restaurant Website

Now that you have setup your restaurant website, here are some top tips that you can use to grow your online business:

We hope this tutorial helped you learn how to create a restaurant website with WordPress. You may also want to see our ultimate WordPress security guide and our expert pick of the must have WordPress plugins that you should install on all business sites.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

The post How to Easily Create a Restaurant Website with WordPress first appeared on WPBeginner.

Building Complex Forms In Vue

More often than not, web engineers always have causes to build out forms, from simple to complex. It is also a familiar pain in the shoe for engineers how fast codebases get incredibly messy and incongruously lengthy when building large and complex forms. Thus begging the question, “How can this be optimized?”.

Consider a business scenario where we need to build a waitlist that captures the name and email. This scenario only requires two/three input fields, as the case may be, and could be added swiftly with little to no hassle. Now, let us consider a different business scenario where users need to fill out a form with ten input fields in 5 sections. Writing 50 input fields isn’t just a tiring job for the Engineer but also a waste of great technical time. More so, it goes against the infamous “Don’t Repeat Yourself” (DRY) principle.

In this article, we will focus on learning to use the Vue components, the v-model directive, and the Vue props to build complex forms in Vue.

The v-model Directive In Vue

Vue has several unique HTML attributes called directives, which are prefixed with the v-. These directives perform different functions, from rendering data in the DOM to manipulating data.

The v-model is one such directive, and it is responsible for two-way data binding between the form input value and the value stored in the data property. The v-model works with any input element, such as the input or the select elements. Under the hood, it combines the inputted input value and the corresponding change event listener like the following:

<!-- Input element -->
<input v-model="inputValue" type="text">

<!-- Select element -->
<select v-model="selectedValue">
  <option value="">Please select the right option</option>
  <option>A</option>
  <option>B</option>
  <option>C</option>
</select>

The input event is used for the <input type= "text"> element. Likewise, for the <select> … </select>, <input type= "checkbox"> and <input type= "radio">, the v-model will, in turn, match the values to a change event.

Components In Vue

Reusability is one of the core principles of Software Engineering, emphasizing on using existing software features or assets in a software project for reasons ranging from minimizing development time to saving cost.

One of the ways we observe reusability in Vue is through the use of components. Vue components are reusable and modular interfaces with their own logic and custom content. Even though they can be nested within each other just as a regular HTML element, they can also work in isolation.

Vue components can be built in two ways as follows:

  • Without the build step,
  • With the build step.

Without The Build Step

Vue components can be created without using the Vue Command Line Interface (CLI). This component creation method defines a JavaScript object in a Vue instance options property. In the code block below, we inlined a JavaScript string that Vue parses on the fly.

template: `
  <p> Vue component without the build step </p>
  `

With The Build Step

Creating components using the build step involves using Vite — a blazingly fast, lightweight build tool. Using the build step to create a Vue component makes a Single File Component (SFC), as it can cater to the file’s logic, content, and styling.

<template>
  <p> Vue component with the build step </p>
</template>

In the above code, we have the <p> tag within the HTML <template> tag, which gets rendered when we use a build step for the application.

Registering Vue Components

Creating a Vue component is the first step of reusability and modularity in Vue. Next is the registration and actual usage of the created Vue component.

Vue components allow the nesting of components within components and, even more, the nesting of components within a global or parent component.

Let’s consider that we stored the component we created using the build step in a BuildStep.vue file. To make this component available for usage, we will import it into another Vue component or a .vue, such as the root entry file. After importing this component, we can then register the component name in the components option property, thus making the component available as an HTML tag. While this HTML tag will have a custom name, the Vue engine will parse them as valid HTML and render them successfully in the browser.

<!-- App.vue -->
<template>
  <div>
    <BuildStep />
  </div>
</template>

<script>
import BuildStep from './BuildStep.vue'

export default {
  components: {
    BuildStep
  }
}
</script>

From the above, we imported the BuildStep.vue component into the App.vue file, registered it in the components option property, and then declared it within our HTML template as <BuildStep />.

Vue Props

Vue props, otherwise known as properties, are custom-made attributes used on a component for passing data from the parent component to the child component(s). A case where props can come in handy is when we need a component with different content but a constant visual layout, considering a component can have as many props as possible.

The Vue prop has a one-way data flow, i.e., from the parent to the child component. Thus, the parent component owns the data, and the child component cannot modify the data. Instead, the child component can emit events that the parent component can record.

Props Declaration In Vue

Let us consider the code block below:

<template>
  <p> Vue component {{ buildType }} the build step</p>
</template>

<script>
export default {
  props: {
    buildType: {
      type: String
    }
  }
}
</script>

We updated the HTML template with the interpolated buildType, which will get executed and replaced with the value of the props that will be passed down from the parent component.

We also added a props tag in the props option property to listen to the props change and update the template accordingly. Within this props option property, we declared the name of the props, which matches what we have in the <template> tag, and also added the props type.

The props type, which can be Strings, Numbers, Arrays, Boolean, or Objects, acts as a rule or check to determine what our component will receive.

In the example above, we added a type of String; we will get an error if we try to pass in any other kind of value like a Boolean or Object.

Passing Props In Vue

To wrap this up, we will update the parent file, i.e., the App.vue, and pass the props accordingly.

<!-- App.vue -->
<template>
  <div>
    <BuildStep buildType="with"/>
  </div>
</template>

<script>
import BuildStep from './BuildStep.vue'

export default {
  components: {
    BuildStep
  }
}
</script>

Now, when the build step component gets rendered, we will see something like the following:

Vue component with the build step

With props, we needn’t create a new component from scratch to display whether a component has a build step or not. We can again declare the <BuildStep /> component and add the relevant build type.

<!-- App..vue -->
<template>
  <div>
    <BuildStep buildType="without"/>
  </div>
</template>

Likewise, just as for the build step, when the component gets rendered, we will have the following view:

Vue component without the build step
Event Handling In Vue

Vue has many directives, which include the v-on. The v-on is responsible for listening and handling DOM events to act when triggered. The v-on directive can also be written as the @ symbol to reduce verbosity.

<button @click="checkBuildType"> Check build type </button>

The button tag in the above code block has a click event attached to a checkBuildType method. When this button gets clicked, it facilitates executing a function that checks for the build type of the component.

Event Modifiers

The v-on directive has several event modifiers that add unique attributes to the v-on event handler. These event modifiers start with a dot and are found right after the event modifier name.

<form @submit.prevent="submitData">
 ...
<!-- This enables a form to be submitted while preventing the page from being reloaded. -->
</form>

Key Modifiers

Key modifiers help us listen to keyboard events, such as enter, and page-up on the fly. Key modifiers are bound to the v-on directive like v-on:eventname.keymodifiername, where the eventname could be keyup and the modifiername as enter.

<input @keyup.enter="checkInput">

The key modifiers also offer flexibility but allow multiple key name chaining.

<input @keyup.ctrl.enter="checkInput">

Here the key names will listen for both the ctrl and the enter keyboard events before the checkInput method gets called.

The v-for Directive

Just as JavaScript provides for iterating through arrays using loops like the for loop, Vue-js also provides a built-in directive known as the v-for that performs the same function.

We can write the v-for syntax as item in items where items are the array we are iterating over or as items of items to express the similarity with the JavaScript loop syntax.

List Rendering

Let us consider rendering the types of component build steps on a page.

<template>
  <div>
    <ul>
        <li v-for="steps in buildSteps" :key="steps.id"> {{ steps.step }}</li>
      </ul>
  </div>
</template>

<script>
export default {
 data() {
   return {
     buildSteps: [
      {
       id: "step 1",
       step:'With the build step',
      },
      {
        id: "step 2",
       step:'Without the build step'
      }
    ]
   }
 }
}
</script>

In the code block above, the steps array within the data property shows the two types of build steps we have for a component. Within our template, we used the v-for directive to loop through the steps array, the result of which we will render in an unordered list.

We added an optional key argument representing the index of the item we are currently iterating on. But beyond that, the key accepts a unique identifier that enables us to track each item’s node for proper state management.

Using v-for With A Component

Just like using the v-for to render lists, we can also use it to generate components. We can add the v-for directive to the component like the following:

<BuildStep v-for="steps in buildSteps" :key="steps.id"/>

The above code block will not do much for rendering or passing the step to the component. Instead, we will need to pass the value of the step as props to the component.

<BuildStep v-for="steps in buildSteps" :key="steps.id" :buildType="steps.step" />

We do the above to prevent any tight fixation of the v-for to the component.

The most important thing to note in the different usage of the v-for is the automation of a long process. We can move from manually listing out 100 items or components to using the v-for directive and have everything rendered out within the split of a second, as the case may be.

Building A Complex Registration Form In Vue

We will combine everything we have learned about the v-model, Vue components, the Vue props, the v-for directive, and event handling to build a complex form that would help us achieve efficiency, scalability, and time management.

This form will cater to capturing students’ bio-data, which we will develop to facilitate progressive enhancement as business demands increase.

Setting Up The Vue App

We will be scaffolding our Vue application using the build step. To do this, we will need to ensure we have the following installed:

Now we will proceed to create our Vue application by running the command below:

# npm
npm init vue@latest vue-complex-form

where vue-complex-form is the name of the Vue application.

After that, we will run the command below at the root of our Vue project:

npm install

Creating The JSON File To Host The Form Data

We aim to create a form where users can fill in their details. While we can manually add all the input fields, we will use a different approach to simplify our codebase. We will achieve this by creating a JSON file called util/bio-data.json. Within each of the JSON objects, we will have the basic info we want each input field to have.

[
  {
    "id": 1,
    "inputvalue":"  ",
    "formdata": "First Name",
    "type": "text",
    "inputdata": "firstname"
  },
  {
    "id": 2,
    "inputvalue":"  ",
    "formdata": "Last Name",
    "type": "text",
    "inputdata": "lastname"
  },
]

As seen in the code block above, we created an object with some keys already carrying values:

  • id acts as the primary identifier of the individual object;
  • inputvalue will cater to the value passed into the v-model;
  • formdata will handle the input placeholder and the labels name;
  • type denotes the input type, such as email, number, or text;
  • inputdata represents the input id and name.

These keys’ values will be passed in later to our component as props. We can access the complete JSON data here.

Creating The Reusable Component

We will create an input component that will get passed the props from the JSON file we created. This input component will get iterated on using a v-for directive to create numerous instances of the input field at a stretch without having to write it all out manually. To do this, we will create a components/TheInputTemplate.vue file and add the code below:

<template>
  <div>
    <label :for="inputData">{{ formData }}</label>
    <input
      :value= "modelValue"
      :type= "type"
      :id= "inputData"
      :name= "inputData"
      :placeholder= "formData"
      @input="$emit('update:modelValue', $event.target.value)"
    >
  </div>
 </template>

<script>
export default {
  name: 'TheInputTemplate',
  props: {
    modelValue: {
      type: String
    },
    formData: {
      type: String
    },
    type: {
      type: String
    },
    inputData: {
      type: String
    }
  },
  emits: ['update:modelValue']
}
</script>
<style>
label {
  display: inline-block;
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  color: rgb(61, 59, 59);
  font-weight: 700;
  font-size: 0.8rem;
}
input {
  display: block;
  width: 90%;
  padding: 0.5rem;
  margin: 0 auto 1.5rem auto;
}
</style>

In the above code block, we achieved the following:

  • We created a component with an input field.
  • Within the input field, we matched the values that we will pass in from the JSON file to the respective places of interest in the element.
  • We also created props of modelValue, formData, type, and inputData that will be registered on the component when exported. These props will be responsible for taking in data from the parent file and passing it down to the TheInputTemplate.vue component.
  • Bound the modelValue prop to the value of the input value.
  • Added the update:modelValue, which gets emitted when the input event is triggered.

Registering The Input Component

We will navigate to our App.vue file and import the TheInputTemplate.vue component from where we can proceed to use it.

<template>
  <form class="wrapper">
    <TheInputTemplate/>
  </form>
</template>
<script>
import TheInputTemplate from './components/TheInputTemplate.vue'
export default {
  name: 'App',
  components: {
    TheInputTemplate
  }
}
</script>
<style>
html, body{
  background-color: grey;
  height: 100%;
  min-height: 100vh;
}
.wrapper {
  background-color: white;
  width: 50%;
  border-radius: 3px;
  padding: 2rem  1.5rem;
  margin: 2rem auto;
}
</style>

Here we imported the TheInputTemplate.vue component into the App.vue file, registered it in the components option property, and then declared it within our HTML template.

If we run npm run serve, we should have the following view:

At this point, there is not much to see because we are yet to register the props on the component.

Passing Input Data

To get the result we are after, we will need to pass the input data and add the props to the component. To do this, we will update our App.vue file:

<template>
  <div class="wrapper">
    <div v-for="bioinfo in biodata" :key="bioinfo.id">
      <TheInputTemplate v-model="bioinfo.inputvalue":formData= "bioinfo.formdata":type= "bioinfo.type":inputData= "bioinfo.inputdata"/>
    </div>
  </div>
<script>
//add imports here
import biodata from "../util/bio-data.json";
export default {
  name: 'App',
 //component goes here
  data: () => ({
    biodata
  })
}
</script>

From the code block above, we achieved several things:

  • We imported the bio-data JSON file we created into the App.vue file. Then we added the imported variable to the data options of the Vue script.
  • Looped through the JSON data, which we instantiated in the data options using the Vue v-for directive.
  • Within the TheInputTemplate.vue component we created, we passed in the suitable data to fill the props option.

At this point, our interface should look like the following:

To confirm if our application is working as it should, we will open up our Vue DevTools, or install one from https://devtools.vuejs.org if we do not have it in our browser yet.

When we type in a value in any of the input fields, we can see the value show up in the modelValue within the Vue Devtools dashboard.

Conclusion

In this article, we explored some core Vue fundamentals like the v-for, v-model, and so on, which we later sewed together to build a complex form. The main goal of this article is to simplify the process of building complex forms while maintaining readability and reusability and reducing development time.

If, in any case, there will be a need to extend the form, all the developer would have to do is populate the JSON files with the needed information, and voila, the form is ready. Also, new Engineers can avoid swimming in lengthy lines of code to get an idea of what is going on in the codebase.

Note: To explore more about handling events within components to deal with as much complexity as possible, you can check out this article on using components with v-model.

Further Reading on Smashing Magazine