All files / src/components FormulateForm.vue

81.25% Statements 13/16
53.85% Branches 7/13
100% Functions 4/4
81.25% Lines 13/16

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                            7x 7x   7x 7x 7x                       12x   12x 60x     12x                 44x 44x     44x 44x                                        
<template>
  <form :class="classes" @submit.prevent="formSubmitted">
    <FormulateSchema
      v-if="schema"
      :schema="schema"
      :hooks="cleanedHooks"
      @events="$emit('events', $event)"
    />
    <FormulateErrors v-if="!hasFormErrorObservers" :context="formContext" />
    <slot />
  </form>
</template>
 
<script>
import { shallowEqualObjects } from "@braid/vue-formulate/src/libs/utils.js";
import Formulate from "@braid/vue-formulate";
 
import { Hooks } from "../libs/hooks.js";
import hooksProp from "../composables/hooksProp.js";
import FormulateSchema from "./FormulateSchema.js";
 
export default {
  extends: Formulate.defaults.components.FormulateForm,
  components: {
    FormulateSchema
  },
  props: {
    hooks: hooksProp
  },
  computed: {
    cleanedHooks() {
      const _hooks = hooksProp.default();
 
      Object.keys(_hooks).forEach(key => {
        _hooks[key] = new Hooks().parse(this.hooks[key]).getHooks();
      });
 
      return Formulate.merge(this.$formulate.options.hooks || {}, _hooks);
    }
  },
  watch: {
    formulateValue: {
      handler(values) {
        /**
         * Overrides the default behavior to properly share v-model updates
         */
E        if (this.isVmodeled && values && typeof values === "object") {
          const keys = Array.from(
            new Set(Object.keys(values).concat(Object.keys(this.proxy)))
          );
          keys.forEach(field => {
I            if (!shallowEqualObjects(values[field], this.proxy[field])) {
              this.setFieldValue(field, values[field]);
              if (
                this.registry.has(field) &&
                !shallowEqualObjects(
                  values[field],
                  this.registry.get(field).proxy
                )
              ) {
                this.registry.get(field).context.model = values[field];
              }
            }
          });
        }
      },
      deep: true
    }
  }
};
</script>