Vuejs method to showcase input fields based on form names

I am working on a Vue.js form component with multiple input fields, but now I need to split it into two separate forms that will collect different user input.

Form 1 includes:

Name
Surname
Email

with a form name attribute value of form_1

Form 2 includes:

Username
Password

with a form name attribute value of form_2

The following code snippet is used:

created: function (formNameAttribute, inputNameAttribute) {

var getForms = document.getElementsByTagName('form');
var inputElement = document.querySelectorAll('input');

for (var i = 0; i < getForms.length; i++) {
  formNameAttribute = getForms[i].name;

  switch (getForms[i].name) {
    case 'Account Details':
      console.log('Form Name: ', getForms[i].name);
      break;

    case 'Account Login':
      console.log('Form Name: ', getForms[i].name);
      break;

    default: 

  }

  for (var j = i; j < inputElement.length; j++) {
    inputNameAttribute = inputElement[j].name;
    console.log('Input name attribute: ', inputNameAttribute);
  }

}

}

I would like to know how to instruct the form component to display only the necessary fields for form_1 and form_2

Link to the external code: Form Component

Answer №1

To include flags as props, you can simply pass them in.

<form-component :info="{ 'username': true, 'password': true }"></form-component>

Additionally,

<input-component v-show="info.password" type="password" placeholder="Enter password" name="password" value=""></input-component>

View the updated jsbin here.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

A guide on how to efficiently retrieve a string within a function in a native module in a React Native

I'm currently tackling a function related to the native elements of iOS that is coded in Objective-C, My goal is to create a method that will output a string in Objective-C, However, I've hit a roadblock while trying to implement this method: T ...

Jquery failing to trigger click() on a div with an id

Within my erb file, there exists a script that looks like the following: function checkJquery() { if(window.jQuery) { jQuery(document).ready(function() { alert('onready'); $('div#habla_topbar_div').click(function( ...

In React components, encountering "cannot read properties of undefined" error occurs, whereas it functions perfectly fine within the getStaticProps

I am currently in the process of setting up a blog using Node.js, React, and graphql. Despite being new to these technologies, including Java and Typescript, I am seeking assistance from anyone who may be able to help. My current roadblock involves display ...

Using Ruby variable as a parameter in JavaScript

Is there a way to include a ruby variable as a parameter in a JavaScript function for a Rails checkbox? Here is an example of what I'm trying to do: <%= check_box_tag 'Sugestão', prato.id , prato.sugestao,:class => prato.categoria_pr ...

Two functions are contained within an object: Function A and Function B. Function A calls Function B from within its own code

If I have two functions within an Object. Object = { Function1() { console.log('Function 1') }, Function2() { this.Function1() } } The Function1 is not being executed. Can someone explain why this is happening an ...

Ways to verify whether an array contains any of the specified objects and then store all those objects in Supabase

Perhaps the title of my question is not very clear, but I find it difficult to summarize in just one line. To provide context, it would be best to see the JavaScript query I'm making for Supabase and its response. The data: [ { title: 'Th ...

Displaying a table in Chrome/Firefox with a mouseover feature

Hovering over the rows of this table triggers a display of descriptions. html: <tr title="{{transaction.submissionLog}}" class="mastertooltip">... JavaScript: $('.masterTooltip').hover(function(){ // Hover functionality ...

Does anyone else have trouble with the Smtp settings and connection on Servage.net? It's driving me crazy, I can't figure it out!

Whenever I attempt to connect to send a servage SMTP, it gives me this error message: SMTP connect() failed. I have tried using the following settings: include('res/mailer/class.phpmailer.php'); $mail->SMTPDebug = 2; include('res/mai ...

Having trouble persisting images in Laravel and Vue Js?

Custom Template <form @submit.prevent=" addUser()"> <div class="form-group"> <label for="addUser">Password</label> <input type="tex" class="form-control" id="name" placeholder="Name" name="name" v-model="form.n ...

What steps can I take to address the problem in iOS 17 where sound is coming from the earpiece instead of the speaker during camera activation?

I have a Progressive Web App where I use the getUserMedia() API to access the camera and HTML audio tags for handling media content. However, ever since updating to iOS 17, I've faced an issue where audio plays through the earpiece instead of the medi ...

AngularJS faces issue with view not reflecting changes made to model

A web-based game I am developing lets players bid on cards and trade them with one another. The technology stack for this application includes Node, Express, MongoDB, and Angular. The player avatars and names, along with their connection status, are displ ...

The Google Maps listener event behaves as if it were clicked even though it is triggered by a mouseover

Two google.maps.event.addListener events are being added here google.maps.event.addListener(markerAcademicCenter, "mouseover", function (e) { markerIconAcademicCenter.url = 'MapIcons/Circle32.png' }); google.maps.event.addListener(markerAcade ...

Updating the scope variable in an AngularJS directive

Recently delving into Angular, I encountered an issue: I have both a list view and a details view with tags. To facilitate navigating between the two views and loading new elements from a service upon click events, I created a directive. My aim is to also ...

Issue encountered while attempting to log out a user using Keycloak in a React JS application

I'm currently working on implementing authentication for a React JS app using Keycloak. To manage the global states, specifically keycloackValue and authenticated in KeycloackContext, I have opted to use React Context. Specific Cases: Upon initial r ...

Issue with combining overflow-x, Firefox, and JavaScript

In Firefox, an issue arises that does not occur in other browsers. To see the problem in action, please visit this example page: -removed- Try selecting a page other than the home page. The window will scroll to your selection. You can then scroll down u ...

Executing webpack with specific settings in Node.js

In my current package.json file, I have a script defined as follows: "build": "webpack --inline --colors --progress --display-error-details --display-cached", Additionally, there is a webpack.config.js file located at the root of my repository. To strea ...

It appears that you are utilizing the runtime-only version of Vue, which does not include the template compiler

When attempting to build my Vue.js application using webpack, a warning appears in the browser. The warning states: "You are using the runtime-only build of Vue where the template compiler is not available. Either pre-compile the templates into render f ...

Utilizing data attributes and JavaScript to dynamically assign a class to carousel navigation items

Hello there! I recently created a carousel and carousel navigation system using Bootstrap. I am now trying to figure out how to detect the value of 'data-slide-to' and then apply a specific style to the corresponding navigation item based on that ...

What is the best way to retrieve the value of a dynamically created button in code?

I am dealing with a situation where I have a button that is supposed to fetch some data based on the classroom ID. button(type='button' id='getButton', onclick='get()', value=classroom.id ) Class Students Additionally, I ha ...

Enhancing the structure and authentication of license plates

I'm having trouble figuring out how to apply Javascript to the text area. Can you advise on whether it's best to use onfocus, onblur, or onclick? Here is the code for the text area: <input type="text" name="c_Kenteken" id="invoerKenteken" cl ...