FormItem.js 1.24 KB
/**
 * 表单域
 *
 * @Author: Shann
 * @LastEditors: Shann
 * @Date: 2021-07-26 08:53:33
 * @LastEditTime: 2021-08-05 14:03:05
 * @FilePath: \angular-js-for-bootstrap\src\Essa\FormItem\FormItem.js
 * @Copyright: Copyright 2021-2021, all rights reserved. Essa.cn
 */
import template from "./FormItem.html";

class FormItem {
    props = {
        name: String,
        label: String,
        labelCol: Object,
        wrapperCol: Object,
        required: Boolean,
    };
    state = {
        labelCol: null,
        wrapperCol: null,
    };

    template = template;

    constructor(esForm) {
        this.esForm = esForm.getContext();

        if (this.props.labelCol && this.props.labelCol.span) {
            this.state.labelCol = this.props.labelCol.span; 
        } else if (
            this.esForm.labelCol &&
            this.esForm.labelCol.span
        ) {
            this.state.labelCol = this.esForm.labelCol.span;
        }

        if (this.props.wrapperCol && this.props.wrapperCol.span) {
            this.state.wrapperCol = this.props.wrapperCol.span;
        } else if (
            this.esForm.wrapperCol &&
            this.esForm.wrapperCol.span
        ) {
            this.state.wrapperCol = this.esForm.wrapperCol.span;
        }
    }
}