MOON
Server: Apache
System: Linux nserver.cafsindia.com 4.18.0-553.123.2.lve.el8.x86_64 #1 SMP Thu May 7 23:17:13 UTC 2026 x86_64
User: cafsindia (1002)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: //home/cafsindia/snap.cafsinfotech.in/node_modules/@cattr/ui-kit/src/components/form/src/form.vue
<template>
  <form
    class="at-form"
    :class="[
      layout ? 'at-form--label-' + layout : '',
      inline ? 'at-form--inline' : '']">
    <slot></slot>
  </form>
</template>

<script>
  export default {
    name: 'AtForm',
    props: {
      model: Object,
      rules: Object,
      labelWidth: Number,
      layout: {
        type: String,
        validator: val => ['horizontal', 'vertical', 'inline'].indexOf(val) > -1
      },
      inline: {
        type: Boolean,
        default: false
      },
      showMessage: {
        type: Boolean,
        default: true
      }
    },
    data () {
      return {
        fields: []
      }
    },
    methods: {
      resetFields () {
        this.fields.forEach(field => {
          field.resetField()
        })
      },
      validate (callback) {
        let valid = true
        let count = 0
        this.fields.forEach(field => {
          field.validate('', errors => {
            if (errors) {
              valid = false
            }
            if (typeof callback === 'function' && (++count) === this.fields.length) {
              callback(valid)
            }
          })
        })
      },
      validateField (prop, callback) {
        const field = this.fields.filter(field => field.prop === prop)[0]

        if (!field) {
          throw new Error('Must call validateField with valid prop string!')
        }

        field.validate('', callback)
      }
    },
    watch: {
      rules () {
        this.validate()
      }
    },
    created () {
      this.$on('on-form-item-add', field => {
        if (field) {
          this.fields.push(field)
        }
      })

      this.$on('on-form-item-remove', field => {
        if (field.prop) {
          this.fields.splice(this.fields.indexOf(field), 1)
        }
      })
    }
  }
</script>