Advertisement
MateusMelo500

Untitled

Oct 13th, 2020
1,948
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 2.78 KB | None | 0 0
  1. <template>
  2.   <div id="app">
  3.     <img alt="Vue logo" src="./assets/logo.png">
  4.     <h1 style="text-align: center">Basic register form</h1>
  5.         <form >
  6.             <p>
  7.                 <label for="name">Name </label>
  8.                 <input v-model="form.name" placeholder="Your name">
  9.             </p>
  10.             <p>
  11.                 <label for="surname">Surname </label>
  12.                 <input v-model="form.surname" placeholder="Your surname"><br>
  13.             </p>
  14.             <p>
  15.                 <label for="email">Email </label>
  16.                 <input v-model="form.email" placeholder="Your email"><br>
  17.             </p>
  18.             <p>
  19.                 <label for="legalPerson">Legal person? </label>
  20.                 <input type="radio" id="yes" v-model="isLegal" v-bind:value="true">
  21.                 <label for="yes">Yes</label>
  22.                 <input type="radio" id="no" v-model="isLegal" v-bind:value="false">
  23.                 <label for="no">No</label><br>
  24.             </p>
  25.             <template v-if="isLegal">
  26.                 <p>
  27.                     <label for="cnpj">CNPJ </label>
  28.                     <input v-model="form.cnpj" placeholder="Your business CNPJ"><br>
  29.                 </p>
  30.             </template>
  31.             <template v-else>
  32.                 <p>
  33.                     <label for="cpf">CPF </label>
  34.                     <input v-model="form.cpf" placeholder="Your CPF"><br>
  35.                 </p>
  36.             </template>
  37.  
  38.             <button v-on:click="submitForm">Save</button>
  39.         </form>
  40.     <!--<template v-if="this.forms.length > 0">-->
  41.         <RegisterTable
  42.             v-for="(form, index) in this.forms"
  43.             v-bind:key="index"
  44.             v-bind:form="form"
  45.         ></RegisterTable>
  46.     <!--</template>-->
  47.   </div>
  48. </template>
  49.  
  50. <script>
  51. import RegisterTable from './components/RegisterTable.vue'
  52.  
  53. export default {
  54.   name: 'App',
  55.   data() {
  56.     return {
  57.         form: {
  58.             name: 'Mateus',
  59.             surname: 'Melo',
  60.             email: 'mateus@mateus.xyz',
  61.             isLegal: false,
  62.             cnpj: '',
  63.             cpf: '12312312323',
  64.         },
  65.         forms: [], // an array to store the forms
  66.         isLegal: false
  67.     }
  68.   },
  69.   components: {
  70.     RegisterTable
  71.   },
  72.   watch: {
  73.     // whenever toggle changes, this function will run
  74.     isLegal: function(val) {
  75.         console.log(val);
  76.       if (val == true) {
  77.         this.showCNPJ();
  78.       } else {
  79.         this.hideCNPJ();
  80.       }
  81.     }
  82.   },
  83.     methods: {
  84.         showCNPJ() {
  85.             this.form.isLegal = this.isLegal;
  86.             this.form.cpf = '';
  87.         },
  88.         hideCNPJ() {
  89.             this.form.isLegal = this.isLegal;
  90.             this.form.cnpj = '';
  91.         },
  92.         submitForm: function(event) {
  93.             //this.forms.push(this.form);
  94.             if (event) {
  95.                 alert(event.target.tagName)
  96.             }
  97.             //this.form = {};
  98.         }
  99.     }
  100. }
  101. </script>
  102.  
  103. <style>
  104. #app {
  105.   font-family: Avenir, Helvetica, Arial, sans-serif;
  106.   -webkit-font-smoothing: antialiased;
  107.   -moz-osx-font-smoothing: grayscale;
  108.   text-align: center;
  109.   color: #2c3e50;
  110.   margin-top: 60px;
  111. }
  112.  
  113. form  {
  114.     margin: 0 auto;
  115.     width: 350px;
  116.     display: table;
  117. }
  118.  
  119. p     {
  120.     display: table-row;
  121. }
  122.  
  123. label {
  124.     text-align: left;
  125.     display: table-cell;
  126. }
  127. input {
  128.     align-items: right;
  129.     display: table-cell;
  130. }
  131. </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement