<template>
  <v-layout>
    <v-flex>
      <form>
        <v-layout align-center justify-left row wrap>
          <v-flex xs12 sm6 lg4 xl3 px-2>
            <v-text-field
              v-model="obj.name"
              v-validate="'required|max:10'"
              :counter="10"
              :error-messages="errors.collect('name')"
              label="Name"
              data-vv-name="name"
              required
            ></v-text-field>
          </v-flex>
          <v-flex xs12 sm6 lg4 xl3 px-2>
            <v-text-field
              v-model="obj.serial"
              v-validate="'required|max:10'"
              :counter="10"
              :error-messages="errors.collect('serial')"
              label="Serial"
              data-vv-name="serial"
              required
            ></v-text-field>
          </v-flex>
          <v-flex xs12 sm6 lg4 xl3 px-2>
            <v-text-field
              v-model="obj.count"
              v-validate="'required|max:10'"
              :counter="10"
              :error-messages="errors.collect('count')"
              label="Count"
              data-vv-name="count"
              required
            ></v-text-field>
          </v-flex>
          <v-flex xs12 sm6 lg4 xl3 px-2>
            <v-text-field
              v-model="obj.dollarAmount"
              v-validate="'required|email'"
              :error-messages="errors.collect('email')"
              label="E-mail"
              data-vv-name="email"
              required
            ></v-text-field>
          </v-flex>
          <v-flex xs12 sm6 lg4 xl3 px-2>
            <v-select
              v-model="select"
              v-validate="'required'"
              :items="items"
              :error-messages="errors.collect('select')"
              label="Select"
              data-vv-name="select"
              required
            ></v-select>
          </v-flex>
          <v-flex xs12 sm6 lg4 xl3 px-2>
            <v-checkbox
              v-model="obj.active"
              v-validate="'required'"
              :error-messages="errors.collect('checkbox')"
              value="1"
              label="Option"
              data-vv-name="checkbox"
              required
            ></v-checkbox>
          </v-flex>
        </v-layout>
        <v-layout align-center justify-space-around row wrap mt-5>
          <v-flex xs1>
            <v-btn @click="clear">clear</v-btn>
          </v-flex>
          <v-flex xs1>
            <v-btn @click="submit">submit</v-btn>
          </v-flex>
        </v-layout>
      </form>
    </v-flex>
  </v-layout>
</template>

<script>
/*  eslint-disable */
// type="checkbox"
//import store from "../store";
import lt from "../api/locale";
//import _ from "../utils/libs/lodash.js";
export default {
  components: {},
  data() {
    return {
      obj: {
        id: 100,
        concurrencyToken: 2675248,
        ownerId: 1,
        name: "Fantastic Wooden Chips 122",
        serial: 100,
        dollarAmount: 584.83,
        active: true,
        roles: 8212,
        startDate: "2019-02-12T10:12:39.594206",
        endDate: "2019-02-12T13:40:59.986405",
        notes:
          "Eum optio incidunt blanditiis laboriosam. Sed ipsam occaecati minus corrupti repudiandae delectus. Culpa nostrum est ullam assumenda animi ut. Velit sunt ex ipsum. Temporibus cum quaerat at omnis at quas. Commodi dolor molestiae beatae.",
        count: 10,
        customFields: null,
        tags: ["brown", "red"]
      }
    }; 
  },
  beforeRouteEnter(to, from, next) {
    //Cache all required lt keys
    var ltKeysRequired = [
      "Widget",
      "WidgetName",
      "WidgetSerial",
      "WidgetDollarAmount",
      "WidgetCount",
      "WidgetRoles",
      "WidgetStartDate",
      "WidgetEndDate",
      "WidgetNotes",
      "WidgetCustom1",
      "WidgetCustom2",
      "WidgetCustom3",
      "WidgetCustom4",
      "WidgetCustom5",
      "WidgetCustom6",
      "WidgetCustom7",
      "WidgetCustom8",
      "WidgetCustom9",
      "WidgetCustom10",
      "WidgetCustom11",
      "WidgetCustom12",
      "WidgetCustom13",
      "WidgetCustom14",
      "WidgetCustom15",
      "WidgetCustom16"
    ].concat(lt.commonKeysEditForm);
    lt.fetch(ltKeysRequired).then(() => {
      next();
    });
  },
  mounted() {},
  methods: {
    lt: function(key) {
      return lt.get(key);
    },
    submit() {
      this.$validator.validateAll();
    }
  }
};
</script>

<style>
</style>

/*
Sample widget record api v8
{
  "data": {
    "id": 100,
    "concurrencyToken": 2675248,
    "ownerId": 1,
    "name": "Fantastic Wooden Chips 122",
    "serial": 100,
    "dollarAmount": 584.83,
    "active": true,
    "roles": 8212,
    "startDate": "2019-02-12T10:12:39.594206",
    "endDate": "2019-02-12T13:40:59.986405",
    "notes": "Eum optio incidunt blanditiis laboriosam. Sed ipsam occaecati minus corrupti repudiandae delectus. Culpa nostrum est ullam assumenda animi ut. Velit sunt ex ipsum. Temporibus cum quaerat at omnis at quas. Commodi dolor molestiae beatae.",
    "count": 0,
    "customFields": null,
    "tags": [
      "brown",
      "red"
    ]
  }
}
*/