Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.0.3/vue.js"></script>
    <title>JS Bin</title>
</head>
<body>
  <div id="app">
    
    <div class="form form_1">
      
      <h4>Form 1</h4>
      
      <form name="Account Details" method="post">
        <form-component :inputs="{ 'username': true, 'password': true }"></form-component>
      </form>
    </div>
    
    <br />
    <br />
    <br />
    
    <div class="form form_2">
      
      <h4>Form 2</h4>
      
      <form name="Account Login" method="post">
        <form-component :inputs="{ 'username': true, 'password': true, 'email': true }"></form-component>
      </form>
    </div>  
    
  </div>
  
  
  
  <template id="formcomp">
    
    <div>
      
      <input-component v-if="inputs.name" type="text" placeholder="Enter name" name="name" value=""></input-component>
      <br />
      <input-component v-if="inputs.surname" type="text" placeholder="Enter surname" name="surname" value=""></input-component>
      <br />
      <input-component v-if="inputs.email" type="email" placeholder="Enter email" name="email" value=""></input-component>
      <br />
      <input-component v-if="inputs.username" type="text" placeholder="Enter username" name="username" value=""></input-component>
      <br />
      <input-component v-if="inputs.password" type="password" placeholder="Enter password" name="password" value=""></input-component>
      
      <br />
      
      <button type="submit">Submit button</button>
      
    </div>
    
  </template>
  
  <template id="inputComponent">
    
    <div>
      
      <input :type="type" :placeholder="placeholder" :name="name" value="" />
      
    </div>
    
  </template>
</body>
</html>
 
Vue.component('form-component', {
  name: 'form',
  template: '#formcomp',
  props: [ 'inputs' ],
  data: function() {
    return {
      
    }
  },
  methods: {
    
  }
  
});
Vue.component('input-component', {
  name: 'input-field',
  template: '#inputComponent',
  props: ['type', 'placeholder', 'name', 'value'],
  data: function() {
    return {
      
    }
  }
  
});
new Vue({
  
  el: '#app',
  data: {
    type: ['text', 'password', 'email', 'number', 'radio', 'checkbox', 'file'],
    placeholder: '',
    name: '',
    formName: '',
    displayInput: true
  },
  methods: {
    
  },
  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);
      }
      
    }
    
  }
  
});
Output

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers