Skip to content

Commit

Permalink
feat(input): add auto-trimming for vxe-table input components (#3684)
Browse files Browse the repository at this point in the history
* fix: Correct spelling errors in form component

* fix: Correct spelling errors in form component

* fix: Correct spelling errors in vxetable component
  • Loading branch information
zandko committed Mar 25, 2024
1 parent 264f34e commit 9882e8d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/components/Form/src/hooks/useFormEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,15 @@ export function useFormEvents({
fieldList = [fields];
}
for (const field of fieldList) {
_removeSchemaByFeild(field, schemaList);
_removeSchemaByField(field, schemaList);
}
schemaRef.value = schemaList;
}

/**
* @description: Delete based on field name
*/
function _removeSchemaByFeild(field: string, schemaList: FormSchema[]): void {
function _removeSchemaByField(field: string, schemaList: FormSchema[]): void {
if (isString(field)) {
const index = schemaList.findIndex((schema) => schema.field === field);
if (index !== -1) {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Form/src/hooks/useFormValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface UseFormValuesContext {
}

/**
* @desription deconstruct array-link key. This method will mutate the target.
* @description deconstruct array-link key. This method will mutate the target.
*/
function tryDeconstructArray(key: string, value: any, target: Recordable) {
const pattern = /^\[(.+)\]$/;
Expand All @@ -31,7 +31,7 @@ function tryDeconstructArray(key: string, value: any, target: Recordable) {
}

/**
* @desription deconstruct object-link key. This method will mutate the target.
* @description deconstruct object-link key. This method will mutate the target.
*/
function tryDeconstructObject(key: string, value: any, target: Recordable) {
const pattern = /^\{(.+)\}$/;
Expand Down
12 changes: 6 additions & 6 deletions src/components/VxeTable/src/components/common.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import XEUtils from 'xe-utils';
import { componentMap } from '../componentMap';
import { ComponentType } from '../componentType';
import { createPlaceholderMessage } from '../helper';
import { createPlaceholderMessage, sanitizeInputWhitespace } from '../helper';

/**
* @description: 获取组件
Expand Down Expand Up @@ -102,13 +102,13 @@ export function createEvents(
};
});
if (inputFunc) {
ons[getOnName(modelEvent)] = function (targetEvnt: any) {
inputFunc(targetEvnt);
ons[getOnName(modelEvent)] = function (targetEvent: any) {
inputFunc(targetEvent);
if (events && events[modelEvent]) {
events[modelEvent](params, targetEvnt);
events[modelEvent](params, targetEvent);
}
if (isSameEvent && changeFunc) {
changeFunc(targetEvnt);
changeFunc(targetEvent);
}
};
}
Expand Down Expand Up @@ -323,7 +323,7 @@ export function createFormItemRender(
params,
(value: any) => {
// 处理 model 值双向绑定
XEUtils.set(data, property, value);
XEUtils.set(data, property, sanitizeInputWhitespace(name as ComponentType, value));
},
() => {
// 处理 change 事件相关逻辑
Expand Down
5 changes: 5 additions & 0 deletions src/components/VxeTable/src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@
* @description: 传给vxe-table 时需要忽略的prop
*/
export const ignorePropKeys = ['tableClass', 'tableStyle'];

/**
* @description: 需要忽略内容首尾空格的输入组件列表
*/
export const ignoreTrimInputComponents = ['AInput', 'ATextarea'];
13 changes: 13 additions & 0 deletions src/components/VxeTable/src/helper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { ComponentType } from './componentType';
import { useI18n } from '@/hooks/web/useI18n';
import XEUtils from 'xe-utils';
import { ignoreTrimInputComponents } from './const';

const { t } = useI18n();

Expand All @@ -17,3 +19,14 @@ export function createPlaceholderMessage(component: ComponentType) {
return t('common.chooseText');
}
}

/**
*
* @description: 对输入值进行首尾空格的清理
*/
export function sanitizeInputWhitespace(component: ComponentType, value: string) {
if (ignoreTrimInputComponents.includes(component)) {
return XEUtils.trim(value);
}
return value;
}

0 comments on commit 9882e8d

Please sign in to comment.