feat: add new form support v-model
parent
f24d8ad7a2
commit
4c3feca9c5
|
@ -1 +1 @@
|
||||||
Subproject commit ce10f4f242cdf252dd25df905bada3b5f7f722e2
|
Subproject commit 9a67d0070ac57b29c70624e8a630e39146b44725
|
|
@ -151,7 +151,7 @@ const Form = {
|
||||||
},
|
},
|
||||||
provide() {
|
provide() {
|
||||||
return {
|
return {
|
||||||
FormContextProps: this,
|
FormContext: this,
|
||||||
// https://github.com/vueComponent/ant-design-vue/issues/446
|
// https://github.com/vueComponent/ant-design-vue/issues/446
|
||||||
collectFormItemContext:
|
collectFormItemContext:
|
||||||
this.form && this.form.templateContext
|
this.form && this.form.templateContext
|
||||||
|
|
|
@ -75,7 +75,7 @@ export default {
|
||||||
},
|
},
|
||||||
inject: {
|
inject: {
|
||||||
isFormItemChildren: { default: false },
|
isFormItemChildren: { default: false },
|
||||||
FormContextProps: { default: () => ({}) },
|
FormContext: { default: () => ({}) },
|
||||||
decoratorFormProps: { default: () => ({}) },
|
decoratorFormProps: { default: () => ({}) },
|
||||||
collectFormItemContext: { default: () => noop },
|
collectFormItemContext: { default: () => noop },
|
||||||
configProvider: { default: () => ConfigConsumerProps },
|
configProvider: { default: () => ConfigConsumerProps },
|
||||||
|
@ -85,7 +85,7 @@ export default {
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
itemSelfUpdate() {
|
itemSelfUpdate() {
|
||||||
return !!(this.selfUpdate === undefined ? this.FormContextProps.selfUpdate : this.selfUpdate);
|
return !!(this.selfUpdate === undefined ? this.FormContext.selfUpdate : this.selfUpdate);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
|
@ -117,8 +117,8 @@ export default {
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
collectContext() {
|
collectContext() {
|
||||||
if (this.FormContextProps.form && this.FormContextProps.form.templateContext) {
|
if (this.FormContext.form && this.FormContext.form.templateContext) {
|
||||||
const { templateContext } = this.FormContextProps.form;
|
const { templateContext } = this.FormContext.form;
|
||||||
const vnodes = Object.values(templateContext.$slots || {}).reduce((a, b) => {
|
const vnodes = Object.values(templateContext.$slots || {}).reduce((a, b) => {
|
||||||
return [...a, ...b];
|
return [...a, ...b];
|
||||||
}, []);
|
}, []);
|
||||||
|
@ -356,9 +356,7 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
renderWrapper(prefixCls, children) {
|
renderWrapper(prefixCls, children) {
|
||||||
const { wrapperCol: contextWrapperCol } = this.isFormItemChildren
|
const { wrapperCol: contextWrapperCol } = this.isFormItemChildren ? {} : this.FormContext;
|
||||||
? {}
|
|
||||||
: this.FormContextProps;
|
|
||||||
const { wrapperCol } = this;
|
const { wrapperCol } = this;
|
||||||
const mergedWrapperCol = wrapperCol || contextWrapperCol || {};
|
const mergedWrapperCol = wrapperCol || contextWrapperCol || {};
|
||||||
const { style, id, on, ...restProps } = mergedWrapperCol;
|
const { style, id, on, ...restProps } = mergedWrapperCol;
|
||||||
|
@ -380,7 +378,7 @@ export default {
|
||||||
labelAlign: contextLabelAlign,
|
labelAlign: contextLabelAlign,
|
||||||
labelCol: contextLabelCol,
|
labelCol: contextLabelCol,
|
||||||
colon: contextColon,
|
colon: contextColon,
|
||||||
} = this.FormContextProps;
|
} = this.FormContext;
|
||||||
const { labelAlign, labelCol, colon, id, htmlFor } = this;
|
const { labelAlign, labelCol, colon, id, htmlFor } = this;
|
||||||
const label = getComponentFromProp(this, 'label');
|
const label = getComponentFromProp(this, 'label');
|
||||||
const required = this.isRequired();
|
const required = this.isRequired();
|
||||||
|
@ -481,8 +479,8 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
decoratorChildren(vnodes) {
|
decoratorChildren(vnodes) {
|
||||||
const { FormContextProps } = this;
|
const { FormContext } = this;
|
||||||
const getFieldDecorator = FormContextProps.form.getFieldDecorator;
|
const getFieldDecorator = FormContext.form.getFieldDecorator;
|
||||||
for (let i = 0, len = vnodes.length; i < len; i++) {
|
for (let i = 0, len = vnodes.length; i < len; i++) {
|
||||||
const vnode = vnodes[i];
|
const vnode = vnodes[i];
|
||||||
if (getSlotOptions(vnode).__ANT_FORM_ITEM) {
|
if (getSlotOptions(vnode).__ANT_FORM_ITEM) {
|
||||||
|
@ -510,7 +508,7 @@ export default {
|
||||||
decoratorFormProps,
|
decoratorFormProps,
|
||||||
fieldDecoratorId,
|
fieldDecoratorId,
|
||||||
fieldDecoratorOptions = {},
|
fieldDecoratorOptions = {},
|
||||||
FormContextProps,
|
FormContext,
|
||||||
} = this;
|
} = this;
|
||||||
let child = filterEmpty($slots.default || []);
|
let child = filterEmpty($slots.default || []);
|
||||||
if (decoratorFormProps.form && fieldDecoratorId && child.length) {
|
if (decoratorFormProps.form && fieldDecoratorId && child.length) {
|
||||||
|
@ -522,7 +520,7 @@ export default {
|
||||||
'`autoFormCreate` just `decorator` then first children. but you can use JSX to support multiple children',
|
'`autoFormCreate` just `decorator` then first children. but you can use JSX to support multiple children',
|
||||||
);
|
);
|
||||||
this.slotDefault = child;
|
this.slotDefault = child;
|
||||||
} else if (FormContextProps.form) {
|
} else if (FormContext.form) {
|
||||||
child = cloneVNodes(child);
|
child = cloneVNodes(child);
|
||||||
this.slotDefault = this.decoratorChildren(child);
|
this.slotDefault = this.decoratorChildren(child);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -56,6 +56,7 @@ import { default as Divider } from './divider';
|
||||||
import { default as Dropdown } from './dropdown';
|
import { default as Dropdown } from './dropdown';
|
||||||
|
|
||||||
import { default as Form } from './form';
|
import { default as Form } from './form';
|
||||||
|
import { default as NewForm } from './n-form';
|
||||||
|
|
||||||
import { default as Icon } from './icon';
|
import { default as Icon } from './icon';
|
||||||
|
|
||||||
|
@ -166,6 +167,7 @@ const components = [
|
||||||
Divider,
|
Divider,
|
||||||
Dropdown,
|
Dropdown,
|
||||||
Form,
|
Form,
|
||||||
|
NewForm,
|
||||||
Icon,
|
Icon,
|
||||||
Input,
|
Input,
|
||||||
InputNumber,
|
InputNumber,
|
||||||
|
@ -254,6 +256,7 @@ export {
|
||||||
Divider,
|
Divider,
|
||||||
Dropdown,
|
Dropdown,
|
||||||
Form,
|
Form,
|
||||||
|
NewForm,
|
||||||
Icon,
|
Icon,
|
||||||
Input,
|
Input,
|
||||||
InputNumber,
|
InputNumber,
|
||||||
|
|
|
@ -161,6 +161,7 @@ export default {
|
||||||
this.removePasswordTimeout = setTimeout(() => {
|
this.removePasswordTimeout = setTimeout(() => {
|
||||||
if (
|
if (
|
||||||
this.$refs.input &&
|
this.$refs.input &&
|
||||||
|
this.$refs.input.getAttribute &&
|
||||||
this.$refs.input.getAttribute('type') === 'password' &&
|
this.$refs.input.getAttribute('type') === 'password' &&
|
||||||
this.$refs.input.hasAttribute('value')
|
this.$refs.input.hasAttribute('value')
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -0,0 +1,189 @@
|
||||||
|
import PropTypes from '../_util/vue-types';
|
||||||
|
import classNames from 'classnames';
|
||||||
|
import { ColProps } from '../grid/Col';
|
||||||
|
import Vue from 'vue';
|
||||||
|
import isRegExp from 'lodash/isRegExp';
|
||||||
|
import warning from '../_util/warning';
|
||||||
|
import createDOMForm from '../vc-form/src/createDOMForm';
|
||||||
|
import createFormField from '../vc-form/src/createFormField';
|
||||||
|
import FormItem from './FormItem';
|
||||||
|
import { FIELD_META_PROP, FIELD_DATA_PROP } from './constants';
|
||||||
|
import { initDefaultProps, getListeners } from '../_util/props-util';
|
||||||
|
import { ConfigConsumerProps } from '../config-provider';
|
||||||
|
import Base from '../base';
|
||||||
|
|
||||||
|
export const FormProps = {
|
||||||
|
layout: PropTypes.oneOf(['horizontal', 'inline', 'vertical']),
|
||||||
|
labelCol: PropTypes.shape(ColProps).loose,
|
||||||
|
wrapperCol: PropTypes.shape(ColProps).loose,
|
||||||
|
colon: PropTypes.bool,
|
||||||
|
labelAlign: PropTypes.oneOf(['left', 'right']),
|
||||||
|
prefixCls: PropTypes.string,
|
||||||
|
hideRequiredMark: PropTypes.bool,
|
||||||
|
model: PropTypes.object,
|
||||||
|
rules: PropTypes.object,
|
||||||
|
validateOnRuleChange: PropTypes.bool,
|
||||||
|
};
|
||||||
|
|
||||||
|
export const ValidationRule = {
|
||||||
|
/** validation error message */
|
||||||
|
message: PropTypes.string,
|
||||||
|
/** built-in validation type, available options: https://github.com/yiminghe/async-validator#type */
|
||||||
|
type: PropTypes.string,
|
||||||
|
/** indicates whether field is required */
|
||||||
|
required: PropTypes.boolean,
|
||||||
|
/** treat required fields that only contain whitespace as errors */
|
||||||
|
whitespace: PropTypes.boolean,
|
||||||
|
/** validate the exact length of a field */
|
||||||
|
len: PropTypes.number,
|
||||||
|
/** validate the min length of a field */
|
||||||
|
min: PropTypes.number,
|
||||||
|
/** validate the max length of a field */
|
||||||
|
max: PropTypes.number,
|
||||||
|
/** validate the value from a list of possible values */
|
||||||
|
enum: PropTypes.oneOfType([String, PropTypes.arrayOf(String)]),
|
||||||
|
/** validate from a regular expression */
|
||||||
|
pattern: PropTypes.custom(isRegExp),
|
||||||
|
/** transform a value before validation */
|
||||||
|
transform: PropTypes.func,
|
||||||
|
/** custom validate function (Note: callback must be called) */
|
||||||
|
validator: PropTypes.func,
|
||||||
|
};
|
||||||
|
|
||||||
|
const Form = {
|
||||||
|
name: 'ANForm',
|
||||||
|
props: initDefaultProps(FormProps, {
|
||||||
|
layout: 'horizontal',
|
||||||
|
hideRequiredMark: false,
|
||||||
|
colon: true,
|
||||||
|
}),
|
||||||
|
Item: FormItem,
|
||||||
|
created() {
|
||||||
|
this.fields = [];
|
||||||
|
},
|
||||||
|
provide() {
|
||||||
|
return {
|
||||||
|
FormContext: this,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
inject: {
|
||||||
|
configProvider: { default: () => ConfigConsumerProps },
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
rules() {
|
||||||
|
if (this.validateOnRuleChange) {
|
||||||
|
this.validate(() => {});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
vertical() {
|
||||||
|
return this.layout === 'vertical';
|
||||||
|
},
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
addField(field) {
|
||||||
|
if (field) {
|
||||||
|
this.fields.push(field);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
removeField(field) {
|
||||||
|
if (field.prop) {
|
||||||
|
this.fields.splice(this.fields.indexOf(field), 1);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onSubmit(e) {
|
||||||
|
if (!getListeners(this).submit) {
|
||||||
|
e.preventDefault();
|
||||||
|
} else {
|
||||||
|
this.$emit('submit', e);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
resetFields() {
|
||||||
|
if (!this.model) {
|
||||||
|
warning(false, 'NewForm', 'model is required for resetFields to work.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.fields.forEach(field => {
|
||||||
|
field.resetField();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
clearValidate(props = []) {
|
||||||
|
const fields = props.length
|
||||||
|
? typeof props === 'string'
|
||||||
|
? this.fields.filter(field => props === field.prop)
|
||||||
|
: this.fields.filter(field => props.indexOf(field.prop) > -1)
|
||||||
|
: this.fields;
|
||||||
|
fields.forEach(field => {
|
||||||
|
field.clearValidate();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
validate(callback) {
|
||||||
|
if (!this.model) {
|
||||||
|
warning(false, 'NewForm', 'model is required for resetFields to work.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let promise;
|
||||||
|
// if no callback, return promise
|
||||||
|
if (typeof callback !== 'function' && window.Promise) {
|
||||||
|
promise = new window.Promise((resolve, reject) => {
|
||||||
|
callback = function(valid) {
|
||||||
|
valid ? resolve(valid) : reject(valid);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
let valid = true;
|
||||||
|
let count = 0;
|
||||||
|
// 如果需要验证的fields为空,调用验证时立刻返回callback
|
||||||
|
if (this.fields.length === 0 && callback) {
|
||||||
|
callback(true);
|
||||||
|
}
|
||||||
|
let invalidFields = {};
|
||||||
|
this.fields.forEach(field => {
|
||||||
|
field.validate('', (message, field) => {
|
||||||
|
if (message) {
|
||||||
|
valid = false;
|
||||||
|
}
|
||||||
|
invalidFields = objectAssign({}, invalidFields, field);
|
||||||
|
if (typeof callback === 'function' && ++count === this.fields.length) {
|
||||||
|
callback(valid, invalidFields);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
if (promise) {
|
||||||
|
return promise;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
validateField(props, cb) {
|
||||||
|
props = [].concat(props);
|
||||||
|
const fields = this.fields.filter(field => props.indexOf(field.prop) !== -1);
|
||||||
|
if (!fields.length) {
|
||||||
|
warning(false, 'NewForm', 'please pass correct props!');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fields.forEach(field => {
|
||||||
|
field.validate('', cb);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const { prefixCls: customizePrefixCls, hideRequiredMark, layout, onSubmit, $slots } = this;
|
||||||
|
const getPrefixCls = this.configProvider.getPrefixCls;
|
||||||
|
const prefixCls = getPrefixCls('form', customizePrefixCls);
|
||||||
|
|
||||||
|
const formClassName = classNames(prefixCls, {
|
||||||
|
[`${prefixCls}-horizontal`]: layout === 'horizontal',
|
||||||
|
[`${prefixCls}-vertical`]: layout === 'vertical',
|
||||||
|
[`${prefixCls}-inline`]: layout === 'inline',
|
||||||
|
[`${prefixCls}-hide-required-mark`]: hideRequiredMark,
|
||||||
|
});
|
||||||
|
return (
|
||||||
|
<form onSubmit={onSubmit} class={formClassName}>
|
||||||
|
{$slots.default}
|
||||||
|
</form>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Form;
|
|
@ -0,0 +1,215 @@
|
||||||
|
import AsyncValidator from 'async-validator';
|
||||||
|
import PropTypes from '../_util/vue-types';
|
||||||
|
import { ColProps } from '../grid/Col';
|
||||||
|
import { initDefaultProps, getComponentFromProp, getOptionProps } from '../_util/props-util';
|
||||||
|
import BaseMixin from '../_util/BaseMixin';
|
||||||
|
import { ConfigConsumerProps } from '../config-provider';
|
||||||
|
import FormItem from '../form/FormItem';
|
||||||
|
|
||||||
|
function noop() {}
|
||||||
|
|
||||||
|
function getPropByPath(obj, path, strict) {
|
||||||
|
let tempObj = obj;
|
||||||
|
path = path.replace(/\[(\w+)\]/g, '.$1');
|
||||||
|
path = path.replace(/^\./, '');
|
||||||
|
|
||||||
|
let keyArr = path.split('.');
|
||||||
|
let i = 0;
|
||||||
|
for (let len = keyArr.length; i < len - 1; ++i) {
|
||||||
|
if (!tempObj && !strict) break;
|
||||||
|
let key = keyArr[i];
|
||||||
|
if (key in tempObj) {
|
||||||
|
tempObj = tempObj[key];
|
||||||
|
} else {
|
||||||
|
if (strict) {
|
||||||
|
throw new Error('please transfer a valid prop path to form item!');
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
o: tempObj,
|
||||||
|
k: keyArr[i],
|
||||||
|
v: tempObj ? tempObj[keyArr[i]] : null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
export const FormItemProps = {
|
||||||
|
id: PropTypes.string,
|
||||||
|
htmlFor: PropTypes.string,
|
||||||
|
prefixCls: PropTypes.string,
|
||||||
|
label: PropTypes.any,
|
||||||
|
help: PropTypes.any,
|
||||||
|
extra: PropTypes.any,
|
||||||
|
labelCol: PropTypes.shape(ColProps).loose,
|
||||||
|
wrapperCol: PropTypes.shape(ColProps).loose,
|
||||||
|
hasFeedback: PropTypes.bool,
|
||||||
|
colon: PropTypes.bool,
|
||||||
|
labelAlign: PropTypes.oneOf(['left', 'right']),
|
||||||
|
name: PropTypes.string,
|
||||||
|
rules: PropTypes.array,
|
||||||
|
required: PropTypes.bool,
|
||||||
|
validateStatus: PropTypes.oneOf(['', 'success', 'warning', 'error', 'validating']),
|
||||||
|
};
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'ANFormItem',
|
||||||
|
__ANT_NEW_FORM_ITEM: true,
|
||||||
|
mixins: [BaseMixin],
|
||||||
|
props: initDefaultProps(FormItemProps, {
|
||||||
|
hasFeedback: false,
|
||||||
|
}),
|
||||||
|
provide() {
|
||||||
|
return {
|
||||||
|
NewFormItemContext: this,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
inject: {
|
||||||
|
configProvider: { default: () => ConfigConsumerProps },
|
||||||
|
FormContext: { default: () => ({}) },
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
validateState: this.validateStatus,
|
||||||
|
validateMessage: '',
|
||||||
|
validateDisabled: false,
|
||||||
|
validator: {},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
computed: {
|
||||||
|
fieldValue() {
|
||||||
|
const model = this.FormContext.model;
|
||||||
|
if (!model || !this.prop) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let path = this.prop;
|
||||||
|
if (path.indexOf(':') !== -1) {
|
||||||
|
path = path.replace(/:/g, '.');
|
||||||
|
}
|
||||||
|
return getPropByPath(model, path, true).v;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
validateStatus(val) {
|
||||||
|
this.validateState = val;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
if (this.prop) {
|
||||||
|
const { addField } = this.FormContext;
|
||||||
|
addField && addField(this);
|
||||||
|
let initialValue = this.fieldValue;
|
||||||
|
if (Array.isArray(initialValue)) {
|
||||||
|
initialValue = [...initialValue];
|
||||||
|
}
|
||||||
|
this.initialValue = initialValue;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
beforeDestroy() {
|
||||||
|
const { removeField } = this.FormContext;
|
||||||
|
removeField && removeField(this);
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
validate(trigger, callback = noop) {
|
||||||
|
this.validateDisabled = false;
|
||||||
|
const rules = this.getFilteredRule(trigger);
|
||||||
|
if ((!rules || rules.length === 0) && this.required === undefined) {
|
||||||
|
callback();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
this.validateState = 'validating';
|
||||||
|
const descriptor = {};
|
||||||
|
if (rules && rules.length > 0) {
|
||||||
|
rules.forEach(rule => {
|
||||||
|
delete rule.trigger;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
descriptor[this.prop] = rules;
|
||||||
|
const validator = new AsyncValidator(descriptor);
|
||||||
|
const model = {};
|
||||||
|
model[this.prop] = this.fieldValue;
|
||||||
|
validator.validate(model, { firstFields: true }, (errors, invalidFields) => {
|
||||||
|
this.validateState = errors ? 'error' : 'success';
|
||||||
|
this.validateMessage = errors ? errors[0].message : '';
|
||||||
|
callback(this.validateMessage, invalidFields);
|
||||||
|
this.FormContext &&
|
||||||
|
this.FormContext.$emit &&
|
||||||
|
this.FormContext.$emit('validate', this.prop, !errors, this.validateMessage || null);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
getRules() {
|
||||||
|
let formRules = this.FormContext.rules || {};
|
||||||
|
const selfRules = this.rules;
|
||||||
|
const requiredRule = this.required !== undefined ? { required: !!this.required } : [];
|
||||||
|
const prop = getPropByPath(formRules, this.prop || '');
|
||||||
|
formRules = formRules ? prop.o[this.prop || ''] || prop.v : [];
|
||||||
|
return [...selfRules, ...formRules, ...requiredRule];
|
||||||
|
},
|
||||||
|
getFilteredRule(trigger) {
|
||||||
|
const rules = this.getRules();
|
||||||
|
return rules
|
||||||
|
.filter(rule => {
|
||||||
|
if (!rule.trigger || trigger === '') return true;
|
||||||
|
if (Array.isArray(rule.trigger)) {
|
||||||
|
return rule.trigger.indexOf(trigger) > -1;
|
||||||
|
} else {
|
||||||
|
return rule.trigger === trigger;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.map(rule => ({ ...rule }));
|
||||||
|
},
|
||||||
|
onFieldBlur() {
|
||||||
|
this.validate('blur');
|
||||||
|
},
|
||||||
|
onFieldChange() {
|
||||||
|
if (this.validateDisabled) {
|
||||||
|
this.validateDisabled = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.validate('change');
|
||||||
|
},
|
||||||
|
clearValidate() {
|
||||||
|
this.validateState = '';
|
||||||
|
this.validateMessage = '';
|
||||||
|
this.validateDisabled = false;
|
||||||
|
},
|
||||||
|
resetField() {
|
||||||
|
this.validateState = '';
|
||||||
|
this.validateMessage = '';
|
||||||
|
let model = this.FormContext.model || {};
|
||||||
|
let value = this.fieldValue;
|
||||||
|
let path = this.prop;
|
||||||
|
if (path.indexOf(':') !== -1) {
|
||||||
|
path = path.replace(/:/, '.');
|
||||||
|
}
|
||||||
|
let prop = getPropByPath(model, path, true);
|
||||||
|
this.validateDisabled = true;
|
||||||
|
if (Array.isArray(value)) {
|
||||||
|
prop.o[prop.k] = [].concat(this.initialValue);
|
||||||
|
} else {
|
||||||
|
prop.o[prop.k] = this.initialValue;
|
||||||
|
}
|
||||||
|
// reset validateDisabled after onFieldChange triggered
|
||||||
|
this.$nextTick(() => {
|
||||||
|
this.validateDisabled = false;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
render() {
|
||||||
|
const { $slots } = this;
|
||||||
|
const props = getOptionProps(this);
|
||||||
|
const label = getComponentFromProp(this, 'label');
|
||||||
|
const extra = getComponentFromProp(this, 'extra');
|
||||||
|
const help = getComponentFromProp(this, 'help');
|
||||||
|
const formProps = {
|
||||||
|
props: {
|
||||||
|
...props,
|
||||||
|
label,
|
||||||
|
extra,
|
||||||
|
validateStatus: this.validateState,
|
||||||
|
help: this.validateMessage || help,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
return <FormItem {...formProps}>{$slots.default}</FormItem>;
|
||||||
|
},
|
||||||
|
};
|
|
@ -0,0 +1,3 @@
|
||||||
|
import demoTest from '../../../tests/shared/demoTest';
|
||||||
|
|
||||||
|
demoTest('n-form');
|
|
@ -0,0 +1,20 @@
|
||||||
|
import Vue from 'vue';
|
||||||
|
import Form from './Form';
|
||||||
|
import ref from 'vue-ref';
|
||||||
|
import FormDecoratorDirective from '../_util/FormDecoratorDirective';
|
||||||
|
import Base from '../base';
|
||||||
|
|
||||||
|
Vue.use(ref, { name: 'ant-ref' });
|
||||||
|
Vue.use(FormDecoratorDirective);
|
||||||
|
|
||||||
|
export { FormProps, ValidationRule } from './Form';
|
||||||
|
export { FormItemProps } from './FormItem';
|
||||||
|
|
||||||
|
/* istanbul ignore next */
|
||||||
|
Form.install = function(Vue) {
|
||||||
|
Vue.use(Base);
|
||||||
|
Vue.component(Form.name, Form);
|
||||||
|
Vue.component(Form.Item.name, Form.Item);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Form;
|
|
@ -0,0 +1,5 @@
|
||||||
|
import '../../style/index.less';
|
||||||
|
import './index.less';
|
||||||
|
|
||||||
|
// style dependencies
|
||||||
|
import '../../grid/style';
|
|
@ -0,0 +1,653 @@
|
||||||
|
@import '../../style/themes/index';
|
||||||
|
@import '../../style/mixins/index';
|
||||||
|
@import '../../input/style/mixin';
|
||||||
|
@import '../../button/style/mixin';
|
||||||
|
@import '../../grid/style/mixin';
|
||||||
|
@import './mixin';
|
||||||
|
|
||||||
|
@form-prefix-cls: ~'@{ant-prefix}-form';
|
||||||
|
@form-component-height: @input-height-base;
|
||||||
|
@form-component-max-height: @input-height-lg;
|
||||||
|
@form-feedback-icon-size: @font-size-base;
|
||||||
|
@form-help-margin-top: (@form-component-height - @form-component-max-height) / 2 + 2px;
|
||||||
|
@form-explain-font-size: @font-size-base;
|
||||||
|
// Extends additional 1px to fix precision issue.
|
||||||
|
// https://github.com/ant-design/ant-design/issues/12803
|
||||||
|
// https://github.com/ant-design/ant-design/issues/8220
|
||||||
|
@form-explain-precision: 1px;
|
||||||
|
@form-explain-height: floor(@form-explain-font-size * @line-height-base);
|
||||||
|
|
||||||
|
.@{form-prefix-cls} {
|
||||||
|
.reset-component;
|
||||||
|
.reset-form;
|
||||||
|
}
|
||||||
|
|
||||||
|
.@{form-prefix-cls}-item-required::before {
|
||||||
|
display: inline-block;
|
||||||
|
margin-right: 4px;
|
||||||
|
color: @label-required-color;
|
||||||
|
font-size: @font-size-base;
|
||||||
|
font-family: SimSun, sans-serif;
|
||||||
|
line-height: 1;
|
||||||
|
content: '*';
|
||||||
|
.@{form-prefix-cls}-hide-required-mark & {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.@{form-prefix-cls}-item-label > label {
|
||||||
|
color: @label-color;
|
||||||
|
|
||||||
|
&::after {
|
||||||
|
& when (@form-item-trailing-colon=true) {
|
||||||
|
content: ':';
|
||||||
|
}
|
||||||
|
& when not (@form-item-trailing-colon=true) {
|
||||||
|
content: ' ';
|
||||||
|
}
|
||||||
|
|
||||||
|
position: relative;
|
||||||
|
top: -0.5px;
|
||||||
|
margin: 0 @form-item-label-colon-margin-right 0 @form-item-label-colon-margin-left;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.@{form-prefix-cls}-item-no-colon::after {
|
||||||
|
content: ' ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Form items
|
||||||
|
// You should wrap labels and controls in .@{form-prefix-cls}-item for optimum spacing
|
||||||
|
.@{form-prefix-cls}-item {
|
||||||
|
label {
|
||||||
|
position: relative;
|
||||||
|
|
||||||
|
> .@{iconfont-css-prefix} {
|
||||||
|
font-size: @font-size-base;
|
||||||
|
vertical-align: top;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.reset-component;
|
||||||
|
|
||||||
|
margin-bottom: @form-item-margin-bottom;
|
||||||
|
vertical-align: top;
|
||||||
|
|
||||||
|
&-control {
|
||||||
|
position: relative;
|
||||||
|
line-height: @form-component-max-height;
|
||||||
|
.clearfix;
|
||||||
|
}
|
||||||
|
|
||||||
|
&-children {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
&-with-help {
|
||||||
|
margin-bottom: max(0, @form-item-margin-bottom - @form-explain-height - @form-help-margin-top);
|
||||||
|
}
|
||||||
|
|
||||||
|
&-label {
|
||||||
|
display: inline-block;
|
||||||
|
overflow: hidden;
|
||||||
|
line-height: @form-component-max-height - 0.0001px;
|
||||||
|
white-space: nowrap;
|
||||||
|
text-align: right;
|
||||||
|
vertical-align: middle;
|
||||||
|
|
||||||
|
&-left {
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.@{ant-prefix}-switch {
|
||||||
|
margin: 2px 0 4px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.@{form-prefix-cls}-explain,
|
||||||
|
.@{form-prefix-cls}-extra {
|
||||||
|
clear: both;
|
||||||
|
min-height: @form-explain-height + @form-explain-precision;
|
||||||
|
margin-top: @form-help-margin-top;
|
||||||
|
color: @text-color-secondary;
|
||||||
|
font-size: @form-explain-font-size;
|
||||||
|
line-height: @line-height-base;
|
||||||
|
transition: color 0.3s @ease-out; // sync input color transition
|
||||||
|
}
|
||||||
|
|
||||||
|
.@{form-prefix-cls}-explain {
|
||||||
|
margin-bottom: -@form-explain-precision;
|
||||||
|
}
|
||||||
|
|
||||||
|
.@{form-prefix-cls}-extra {
|
||||||
|
padding-top: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.@{form-prefix-cls}-text {
|
||||||
|
display: inline-block;
|
||||||
|
padding-right: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.@{form-prefix-cls}-split {
|
||||||
|
display: block;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
form {
|
||||||
|
.has-feedback {
|
||||||
|
.@{ant-prefix}-input {
|
||||||
|
padding-right: @input-padding-horizontal-base + @input-affix-width;
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://github.com/ant-design/ant-design/issues/19884
|
||||||
|
.@{ant-prefix}-input-affix-wrapper {
|
||||||
|
.@{ant-prefix}-input-suffix {
|
||||||
|
padding-right: 18px;
|
||||||
|
}
|
||||||
|
.@{ant-prefix}-input {
|
||||||
|
padding-right: @input-padding-horizontal-base + @input-affix-width * 2;
|
||||||
|
}
|
||||||
|
&.@{ant-prefix}-input-affix-wrapper-input-with-clear-btn {
|
||||||
|
.@{ant-prefix}-input {
|
||||||
|
padding-right: @input-padding-horizontal-base + @input-affix-width * 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fix overlapping between feedback icon and <Select>'s arrow.
|
||||||
|
// https://github.com/ant-design/ant-design/issues/4431
|
||||||
|
> .@{ant-prefix}-select .@{ant-prefix}-select-arrow,
|
||||||
|
> .@{ant-prefix}-select .@{ant-prefix}-select-selection__clear,
|
||||||
|
:not(.@{ant-prefix}-input-group-addon) > .@{ant-prefix}-select .@{ant-prefix}-select-arrow,
|
||||||
|
:not(.@{ant-prefix}-input-group-addon)
|
||||||
|
> .@{ant-prefix}-select
|
||||||
|
.@{ant-prefix}-select-selection__clear {
|
||||||
|
right: (@form-component-height / 2) + @form-feedback-icon-size - 2px;
|
||||||
|
}
|
||||||
|
> .@{ant-prefix}-select .@{ant-prefix}-select-selection-selected-value,
|
||||||
|
:not(.@{ant-prefix}-input-group-addon)
|
||||||
|
> .@{ant-prefix}-select
|
||||||
|
.@{ant-prefix}-select-selection-selected-value {
|
||||||
|
padding-right: 42px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.@{ant-prefix}-cascader-picker {
|
||||||
|
&-arrow {
|
||||||
|
margin-right: (@form-component-height / 2) + @form-feedback-icon-size - 13px;
|
||||||
|
}
|
||||||
|
&-clear {
|
||||||
|
right: (@form-component-height / 2) + @form-feedback-icon-size - 2px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fix issue: https://github.com/ant-design/ant-design/issues/7854
|
||||||
|
.@{ant-prefix}-input-search:not(.@{ant-prefix}-input-search-enter-button) {
|
||||||
|
.@{ant-prefix}-input-suffix {
|
||||||
|
right: (@form-component-height / 2) + @form-feedback-icon-size - 2px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fix issue: https://github.com/ant-design/ant-design/issues/4783
|
||||||
|
.@{ant-prefix}-calendar-picker,
|
||||||
|
.@{ant-prefix}-time-picker {
|
||||||
|
&-icon,
|
||||||
|
&-clear {
|
||||||
|
right: (@form-component-height / 2) + @form-feedback-icon-size - 2px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.@{ant-prefix}-mentions,
|
||||||
|
textarea.@{ant-prefix}-input {
|
||||||
|
height: auto;
|
||||||
|
margin-bottom: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
// input[type=file]
|
||||||
|
.@{ant-prefix}-upload {
|
||||||
|
background: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type='radio'],
|
||||||
|
input[type='checkbox'] {
|
||||||
|
width: 14px;
|
||||||
|
height: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Radios and checkboxes on same line
|
||||||
|
.@{ant-prefix}-radio-inline,
|
||||||
|
.@{ant-prefix}-checkbox-inline {
|
||||||
|
display: inline-block;
|
||||||
|
margin-left: 8px;
|
||||||
|
font-weight: normal;
|
||||||
|
vertical-align: middle;
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
|
&:first-child {
|
||||||
|
margin-left: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.@{ant-prefix}-checkbox-vertical,
|
||||||
|
.@{ant-prefix}-radio-vertical {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.@{ant-prefix}-checkbox-vertical + .@{ant-prefix}-checkbox-vertical,
|
||||||
|
.@{ant-prefix}-radio-vertical + .@{ant-prefix}-radio-vertical {
|
||||||
|
margin-left: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.@{ant-prefix}-input-number {
|
||||||
|
+ .@{form-prefix-cls}-text {
|
||||||
|
margin-left: 8px;
|
||||||
|
}
|
||||||
|
&-handler-wrap {
|
||||||
|
z-index: 2; // https://github.com/ant-design/ant-design/issues/6289
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.@{ant-prefix}-select,
|
||||||
|
.@{ant-prefix}-cascader-picker {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Don't impact select inside input group
|
||||||
|
.@{ant-prefix}-input-group .@{ant-prefix}-select,
|
||||||
|
.@{ant-prefix}-input-group .@{ant-prefix}-cascader-picker {
|
||||||
|
width: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
// fix input with addon position. https://github.com/ant-design/ant-design/issues/8243
|
||||||
|
:not(.@{ant-prefix}-input-group-wrapper) > .@{ant-prefix}-input-group,
|
||||||
|
.@{ant-prefix}-input-group-wrapper {
|
||||||
|
display: inline-block;
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://github.com/ant-design/ant-design/issues/20616
|
||||||
|
&:not(.@{form-prefix-cls}-vertical) {
|
||||||
|
:not(.@{ant-prefix}-input-group-wrapper) > .@{ant-prefix}-input-group,
|
||||||
|
.@{ant-prefix}-input-group-wrapper {
|
||||||
|
position: relative;
|
||||||
|
top: -1px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Form layout
|
||||||
|
//== Vertical Form
|
||||||
|
.make-vertical-layout-label() {
|
||||||
|
display: block;
|
||||||
|
margin: @form-vertical-label-margin;
|
||||||
|
padding: @form-vertical-label-padding;
|
||||||
|
line-height: @line-height-base;
|
||||||
|
white-space: initial;
|
||||||
|
text-align: left;
|
||||||
|
|
||||||
|
label::after {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.make-vertical-layout() {
|
||||||
|
.@{form-prefix-cls}-item-label,
|
||||||
|
.@{form-prefix-cls}-item-control-wrapper {
|
||||||
|
display: block;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
.@{form-prefix-cls}-item-label {
|
||||||
|
.make-vertical-layout-label();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.@{form-prefix-cls}-vertical .@{form-prefix-cls}-item-label,
|
||||||
|
// when labelCol is 24, it is a vertical form
|
||||||
|
.@{ant-prefix}-col-24.@{form-prefix-cls}-item-label,
|
||||||
|
.@{ant-prefix}-col-xl-24.@{form-prefix-cls}-item-label {
|
||||||
|
.make-vertical-layout-label();
|
||||||
|
}
|
||||||
|
|
||||||
|
.@{form-prefix-cls}-vertical {
|
||||||
|
.@{form-prefix-cls}-item {
|
||||||
|
padding-bottom: 8px;
|
||||||
|
}
|
||||||
|
.@{form-prefix-cls}-item-control {
|
||||||
|
line-height: @line-height-base;
|
||||||
|
}
|
||||||
|
.@{form-prefix-cls}-explain {
|
||||||
|
margin-top: 2px;
|
||||||
|
margin-bottom: -4px - @form-explain-precision;
|
||||||
|
}
|
||||||
|
.@{form-prefix-cls}-extra {
|
||||||
|
margin-top: 2px;
|
||||||
|
margin-bottom: -4px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: @screen-xs-max) {
|
||||||
|
.make-vertical-layout();
|
||||||
|
.@{ant-prefix}-col-xs-24.@{form-prefix-cls}-item-label {
|
||||||
|
.make-vertical-layout-label();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: @screen-sm-max) {
|
||||||
|
.@{ant-prefix}-col-sm-24.@{form-prefix-cls}-item-label {
|
||||||
|
.make-vertical-layout-label();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: @screen-md-max) {
|
||||||
|
.@{ant-prefix}-col-md-24.@{form-prefix-cls}-item-label {
|
||||||
|
.make-vertical-layout-label();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: @screen-lg-max) {
|
||||||
|
.@{ant-prefix}-col-lg-24.@{form-prefix-cls}-item-label {
|
||||||
|
.make-vertical-layout-label();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: @screen-xl-max) {
|
||||||
|
.@{ant-prefix}-col-xl-24.@{form-prefix-cls}-item-label {
|
||||||
|
.make-vertical-layout-label();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//== Inline Form
|
||||||
|
.@{form-prefix-cls}-inline {
|
||||||
|
.@{form-prefix-cls}-item {
|
||||||
|
display: inline-block;
|
||||||
|
margin-right: 16px;
|
||||||
|
margin-bottom: 0;
|
||||||
|
|
||||||
|
&-with-help {
|
||||||
|
margin-bottom: @form-item-margin-bottom;
|
||||||
|
}
|
||||||
|
|
||||||
|
> .@{form-prefix-cls}-item-control-wrapper,
|
||||||
|
> .@{form-prefix-cls}-item-label {
|
||||||
|
display: inline-block;
|
||||||
|
vertical-align: top;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.@{form-prefix-cls}-text {
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.has-feedback {
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validation state
|
||||||
|
.has-success,
|
||||||
|
.has-warning,
|
||||||
|
.has-error,
|
||||||
|
.is-validating {
|
||||||
|
&.has-feedback .@{form-prefix-cls}-item-children-icon {
|
||||||
|
position: absolute;
|
||||||
|
top: 50%;
|
||||||
|
right: 0;
|
||||||
|
z-index: 1;
|
||||||
|
width: @form-component-height;
|
||||||
|
height: 20px;
|
||||||
|
margin-top: -10px;
|
||||||
|
font-size: @form-feedback-icon-size;
|
||||||
|
line-height: 20px;
|
||||||
|
text-align: center;
|
||||||
|
visibility: visible;
|
||||||
|
animation: zoomIn 0.3s @ease-out-back;
|
||||||
|
pointer-events: none;
|
||||||
|
|
||||||
|
& svg {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
margin: auto;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.has-success {
|
||||||
|
&.has-feedback .@{form-prefix-cls}-item-children-icon {
|
||||||
|
color: @success-color;
|
||||||
|
animation-name: diffZoomIn1 !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.has-warning {
|
||||||
|
.form-control-validation(@warning-color; @warning-color; @form-warning-input-bg;);
|
||||||
|
|
||||||
|
&.has-feedback .@{form-prefix-cls}-item-children-icon {
|
||||||
|
color: @warning-color;
|
||||||
|
animation-name: diffZoomIn3 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
//select
|
||||||
|
.@{ant-prefix}-select {
|
||||||
|
&-selection {
|
||||||
|
border-color: @warning-color;
|
||||||
|
&:hover {
|
||||||
|
border-color: @warning-color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
&-open .@{ant-prefix}-select-selection,
|
||||||
|
&-focused .@{ant-prefix}-select-selection {
|
||||||
|
.active(@warning-color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// arrow and icon
|
||||||
|
.@{ant-prefix}-calendar-picker-icon::after,
|
||||||
|
.@{ant-prefix}-time-picker-icon::after,
|
||||||
|
.@{ant-prefix}-picker-icon::after,
|
||||||
|
.@{ant-prefix}-select-arrow,
|
||||||
|
.@{ant-prefix}-cascader-picker-arrow {
|
||||||
|
color: @warning-color;
|
||||||
|
}
|
||||||
|
|
||||||
|
//input-number, timepicker
|
||||||
|
.@{ant-prefix}-input-number,
|
||||||
|
.@{ant-prefix}-time-picker-input {
|
||||||
|
border-color: @warning-color;
|
||||||
|
&-focused,
|
||||||
|
&:focus {
|
||||||
|
.active(@warning-color);
|
||||||
|
}
|
||||||
|
&:not([disabled]):hover {
|
||||||
|
border-color: @warning-color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.@{ant-prefix}-cascader-picker {
|
||||||
|
&:focus .@{ant-prefix}-cascader-input {
|
||||||
|
.active(@warning-color);
|
||||||
|
}
|
||||||
|
&:hover .@{ant-prefix}-cascader-input {
|
||||||
|
border-color: @warning-color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.has-error {
|
||||||
|
.form-control-validation(@error-color; @error-color; @form-error-input-bg;);
|
||||||
|
|
||||||
|
&.has-feedback .@{form-prefix-cls}-item-children-icon {
|
||||||
|
color: @error-color;
|
||||||
|
animation-name: diffZoomIn2 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
//select
|
||||||
|
.@{ant-prefix}-select {
|
||||||
|
&-selection {
|
||||||
|
border-color: @error-color;
|
||||||
|
&:hover {
|
||||||
|
border-color: @error-color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
&-open .@{ant-prefix}-select-selection,
|
||||||
|
&-focused .@{ant-prefix}-select-selection {
|
||||||
|
.active(@error-color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.@{ant-prefix}-select.@{ant-prefix}-select-auto-complete {
|
||||||
|
.@{ant-prefix}-input:focus {
|
||||||
|
border-color: @error-color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.@{ant-prefix}-input-group-addon .@{ant-prefix}-select {
|
||||||
|
&-selection {
|
||||||
|
border-color: transparent;
|
||||||
|
box-shadow: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// arrow and icon
|
||||||
|
.@{ant-prefix}-calendar-picker-icon::after,
|
||||||
|
.@{ant-prefix}-time-picker-icon::after,
|
||||||
|
.@{ant-prefix}-picker-icon::after,
|
||||||
|
.@{ant-prefix}-select-arrow,
|
||||||
|
.@{ant-prefix}-cascader-picker-arrow {
|
||||||
|
color: @error-color;
|
||||||
|
}
|
||||||
|
|
||||||
|
//input-number, timepicker
|
||||||
|
.@{ant-prefix}-input-number,
|
||||||
|
.@{ant-prefix}-time-picker-input {
|
||||||
|
border-color: @error-color;
|
||||||
|
&-focused,
|
||||||
|
&:focus {
|
||||||
|
.active(@error-color);
|
||||||
|
}
|
||||||
|
&:not([disabled]):hover {
|
||||||
|
border-color: @error-color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.@{ant-prefix}-mention-wrapper {
|
||||||
|
.@{ant-prefix}-mention-editor {
|
||||||
|
&,
|
||||||
|
&:not([disabled]):hover {
|
||||||
|
border-color: @error-color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
&.@{ant-prefix}-mention-active:not([disabled]) .@{ant-prefix}-mention-editor,
|
||||||
|
.@{ant-prefix}-mention-editor:not([disabled]):focus {
|
||||||
|
.active(@error-color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.@{ant-prefix}-cascader-picker {
|
||||||
|
&:focus .@{ant-prefix}-cascader-input {
|
||||||
|
.active(@error-color);
|
||||||
|
}
|
||||||
|
&:hover .@{ant-prefix}-cascader-input {
|
||||||
|
border-color: @error-color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// transfer
|
||||||
|
.@{ant-prefix}-transfer {
|
||||||
|
&-list {
|
||||||
|
border-color: @error-color;
|
||||||
|
|
||||||
|
&-search:not([disabled]) {
|
||||||
|
border-color: @input-border-color;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
.hover();
|
||||||
|
}
|
||||||
|
|
||||||
|
&:focus {
|
||||||
|
.active();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.is-validating {
|
||||||
|
&.has-feedback .@{form-prefix-cls}-item-children-icon {
|
||||||
|
display: inline-block;
|
||||||
|
color: @primary-color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.@{ant-prefix}-advanced-search-form {
|
||||||
|
.@{form-prefix-cls}-item {
|
||||||
|
margin-bottom: @form-item-margin-bottom;
|
||||||
|
|
||||||
|
&-with-help {
|
||||||
|
margin-bottom: @form-item-margin-bottom - @form-explain-height - @form-help-margin-top;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.show-help-motion(@className, @keyframeName, @duration: @animation-duration-slow) {
|
||||||
|
.make-motion(@className, @keyframeName, @duration);
|
||||||
|
.@{className}-enter,
|
||||||
|
.@{className}-appear {
|
||||||
|
opacity: 0;
|
||||||
|
animation-timing-function: @ease-in-out;
|
||||||
|
}
|
||||||
|
.@{className}-leave {
|
||||||
|
animation-timing-function: @ease-in-out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.show-help-motion(show-help, antShowHelp, 0.3s);
|
||||||
|
|
||||||
|
@keyframes antShowHelpIn {
|
||||||
|
0% {
|
||||||
|
transform: translateY(-5px);
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
transform: translateY(0);
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes antShowHelpOut {
|
||||||
|
to {
|
||||||
|
transform: translateY(-5px);
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// need there different zoom animation
|
||||||
|
// otherwise won't trigger anim
|
||||||
|
@keyframes diffZoomIn1 {
|
||||||
|
0% {
|
||||||
|
transform: scale(0);
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
transform: scale(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes diffZoomIn2 {
|
||||||
|
0% {
|
||||||
|
transform: scale(0);
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
transform: scale(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes diffZoomIn3 {
|
||||||
|
0% {
|
||||||
|
transform: scale(0);
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
transform: scale(1);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,126 @@
|
||||||
|
@import '../../input/style/mixin';
|
||||||
|
|
||||||
|
.form-control-validation(@text-color: @input-color; @border-color: @input-border-color; @background-color: @input-bg) {
|
||||||
|
.@{ant-prefix}-form-explain,
|
||||||
|
.@{ant-prefix}-form-split {
|
||||||
|
color: @text-color;
|
||||||
|
}
|
||||||
|
// 输入框的不同校验状态
|
||||||
|
.@{ant-prefix}-input {
|
||||||
|
&,
|
||||||
|
&:hover {
|
||||||
|
background-color: @background-color;
|
||||||
|
border-color: @border-color;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:focus {
|
||||||
|
.active(@border-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
&:not([disabled]):hover {
|
||||||
|
border-color: @border-color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.@{ant-prefix}-calendar-picker-open .@{ant-prefix}-calendar-picker-input {
|
||||||
|
.active(@border-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Input prefix
|
||||||
|
.@{ant-prefix}-input-affix-wrapper {
|
||||||
|
.@{ant-prefix}-input {
|
||||||
|
&,
|
||||||
|
&:hover {
|
||||||
|
background-color: @background-color;
|
||||||
|
border-color: @border-color;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:focus {
|
||||||
|
.active(@border-color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&:hover .@{ant-prefix}-input:not(.@{ant-prefix}-input-disabled) {
|
||||||
|
border-color: @border-color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.@{ant-prefix}-input-prefix {
|
||||||
|
color: @text-color;
|
||||||
|
}
|
||||||
|
|
||||||
|
.@{ant-prefix}-input-group-addon {
|
||||||
|
color: @text-color;
|
||||||
|
background-color: @background-color;
|
||||||
|
border-color: @border-color;
|
||||||
|
}
|
||||||
|
|
||||||
|
.has-feedback {
|
||||||
|
color: @text-color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset form styles
|
||||||
|
// -----------------------------
|
||||||
|
// Based on Bootstrap framework
|
||||||
|
.reset-form() {
|
||||||
|
legend {
|
||||||
|
display: block;
|
||||||
|
width: 100%;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
padding: 0;
|
||||||
|
color: @text-color-secondary;
|
||||||
|
font-size: @font-size-lg;
|
||||||
|
line-height: inherit;
|
||||||
|
border: 0;
|
||||||
|
border-bottom: @border-width-base @border-style-base @border-color-base;
|
||||||
|
}
|
||||||
|
|
||||||
|
label {
|
||||||
|
font-size: @font-size-base;
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type='search'] {
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Position radios and checkboxes better
|
||||||
|
input[type='radio'],
|
||||||
|
input[type='checkbox'] {
|
||||||
|
line-height: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type='file'] {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make range inputs behave like textual form controls
|
||||||
|
input[type='range'] {
|
||||||
|
display: block;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make multiple select elements height not fixed
|
||||||
|
select[multiple],
|
||||||
|
select[size] {
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Focus for file, radio, and checkbox
|
||||||
|
input[type='file']:focus,
|
||||||
|
input[type='radio']:focus,
|
||||||
|
input[type='checkbox']:focus {
|
||||||
|
outline: thin dotted;
|
||||||
|
outline: 5px auto -webkit-focus-ring-color;
|
||||||
|
outline-offset: -2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Adjust output element
|
||||||
|
output {
|
||||||
|
display: block;
|
||||||
|
padding-top: 15px;
|
||||||
|
color: @input-color;
|
||||||
|
font-size: @font-size-base;
|
||||||
|
line-height: @line-height-base;
|
||||||
|
}
|
||||||
|
}
|
|
@ -59,3 +59,4 @@ import './statistic/style';
|
||||||
import './result/style';
|
import './result/style';
|
||||||
import './descriptions/style';
|
import './descriptions/style';
|
||||||
import './page-header/style';
|
import './page-header/style';
|
||||||
|
import './n-form/style';
|
||||||
|
|
Loading…
Reference in New Issue