FormItem.js
1.28 KB
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
/**
* 表单域
*/
import template from "./FormItem.html";
angular.module("esNgAntd").directive("antdFormItem", function () {
return {
template: template,
restrict: "E",
replace: true,
transclude: true,
scope: {
name: "@",
label: "@",
labelCol: "=",
wrapperCol: "=",
required: "="
},
require: ["^?antdForm"],
controller: function ($scope, $element, $attrs) {
this.getContext = function () {
return $scope;
};
$scope.state = {
labelCol: null,
wrapperCol: null
};
},
link: function ($scope, $element, $attrs, $controllers) {
let [antdForm] = $controllers;
if (antdForm) {
$scope.antdForm = antdForm.getContext();
}
if ($scope.labelCol && $scope.labelCol.span) {
$scope.state.labelCol = $scope.labelCol.span;
} else if ($scope.antdForm.labelCol && $scope.antdForm.labelCol.span) {
$scope.state.labelCol = $scope.antdForm.labelCol.span;
}
if ($scope.wrapperCol && $scope.wrapperCol.span) {
$scope.state.wrapperCol = $scope.wrapperCol.span;
} else if ($scope.antdForm.wrapperCol && $scope.antdForm.wrapperCol.span) {
$scope.state.wrapperCol = $scope.antdForm.wrapperCol.span;
}
}
};
});