All files / components/utilities/form-utils form-comp.vue

0% Statements 0/6
0% Branches 0/3
0% Functions 0/4
0% Lines 0/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192                                                                                                                                                                                                                                                                                                                                                                                               
<template>
  <div class="form-container w-100">
    <form @submit.prevent="$emit('submit')" novalidate class="d-flex flex-column align-items-center">
 
      <input-label
        v-for="(field, index) in formSpecs['fields']"
        :class="{'mb-2': index === formSpecs['fields'].length - 1, 'mb-3': index < formSpecs['fields'].length - 1}"
        :key="index"
        :inputSpecs="{
          label: false,
          index: index,
          type: field.type,
          name: field.name,
          task: formSpecs['task'],
          placeholder: field.name
        }"/>
 
      <div v-if="formSpecs['checkboxLabel']" class="form-check align-self-start mt-2">
        <input class="form-check-input shadow-none align-self-start" type="checkbox" v-model="checkboxValue"
               id="form-checkbox" required>
        <label class="form-check-label" for="form-checkbox">
          {{ this.formSpecs['checkboxLabel'] }}
        </label>
      </div>
 
      <p v-if="isResetPassEmail" id="check-email">Link-ul pentru resetarea parolei a fost trimis pe adresa de email
        specificata</p>
      <p id="error" class="mt-2" v-if="getError && formSpecs['task'] !== 'newsletter'">{{ getError }}</p>
      <input type="submit" :class="{'disabled': isDisabled, 'my-5': formSpecs['task'] !== 'newsletter'}"
             class="submit-button p-1 p-sm-2 p-md-3 p-lg-2" :value="formSpecs['submitText']">
    </form>
  </div>
</template>
 
<script>
import inputLabel from './input-label.vue';
import {mapGetters, mapMutations} from "vuex";
import Product from "../../products/product";
 
export default {
  components: {Product, inputLabel},
  data() {
    return {
      checkboxValue: false
    }
  },
  emits: ['submit'],
  props: ['formSpecs'],
  computed: {
    ...mapGetters({isResetPassEmail: 'isResetPassEmail', getError: 'error'}),
 
    /**
     * Enables submit button only when all fields are filled in
     * @see isDisabled
     * @returns boolean
     */
    isDisabled() {
      return this.formSpecs['fields'].filter(elem => elem.value).length !== this.formSpecs['fields'].length || (!this.checkboxValue && this.formSpecs['checkboxLabel']);
    }
  },
 
  methods: {
    ...mapMutations(['changeError'])
  },
 
  watch: {
    /**
     * Resets error when user starts typing
     * @see fields
     * @returns void
     */
    'formSpecs.fields': function () {
      this.changeError('');
    }
  }
}
</script>
 
<style lang="scss" scoped>
 
#error {
  color: red;
  font-size: 1rem;
}
 
.disabled {
  opacity: 0.5;
  pointer-events: none;
}
 
.form-check-input {
  position: relative;
  bottom: -0.1rem;
  width: 0.9rem;
  height: 0.9rem;
  //border-radius: 0;
}
 
.form-check-input, .form-check-input:focus {
  border: 1px solid rgb(154, 117, 63);
}
 
.form-check-label {
  color: rgb(154, 117, 63);
  font-size: 1rem;
}
 
.submit-button {
  margin-top: 2rem;
  font-size: 1rem;
  background-color: white;
  font-family: SoleilBold;
  width: 75%;
  border: 1px solid rgb(154, 117, 63);
  color: rgb(154, 117, 63);
}
 
@include media-breakpoint-up(lg) {
  .submit-button:hover {
    background-color: rgb(154, 117, 63);
    color: white;
  }
}
 
@media screen and #{$ipad-pro-landscape-breakpoint},
screen and #{$ipad-pro-portrait-breakpoint},
screen and #{$ipad-landscape-breakpoint} {
 
  .form-check {
    margin-top: $spacer * 1.5 !important;
  }
 
  .form-check-label {
    font-size: 1.6rem;
    text-align: justify;
  }
 
  .form-check-input {
    width: 1.4rem;
    height: 1.4rem;
  }
 
  .submit-button {
    font-size: 1.6rem;
    width: 100%;
  }
 
  #error {
    font-size: 1.6rem;
  }
}
 
@include media-breakpoint-down(lg) {
 
  .form-check-label {
    font-size: 1.2rem;
    text-align: justify;
  }
 
  .form-check-input {
    width: 1.2rem;
    height: 1.2rem;
  }
 
  .submit-button {
    font-size: 1.4rem;
    width: 100%;
  }
 
  #error {
    font-size: 1.4rem;
  }
}
 
@include media-breakpoint-down(sm) {
  .submit-button, #error {
    font-size: 1.2rem;
  }
 
  .form-check-label {
    font-size: 1rem;
  }
 
  .form-check-input {
    width: 1rem;
    height: 1rem;
  }
}
 
 
</style>