Skip to content

Commit fa174a4

Browse files
committed
!440 fix(form): 单个form-item必填未触发表单校验回调
* fix(form): 单个form-item必填未触发表单校验回调
1 parent 6fa5135 commit fa174a4

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

packages/component/component/form/__tests__/form.test.tsx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,44 @@ describe("LayForm", () => {
113113
expect(fn.mock.calls[0][0]).toBeTruthy();
114114
});
115115
});
116+
117+
describe("validator", () => {
118+
function createForm() {
119+
const model = reactive({
120+
account: "",
121+
password: "",
122+
});
123+
124+
const wrapper = mount({
125+
setup() {
126+
return () => (
127+
<LayForm model={model}>
128+
<LayFormItem label="账号" prop="account">
129+
<LayInput v-model={model.account}></LayInput>
130+
</LayFormItem>
131+
<LayFormItem label="密码" prop="password" required={true}>
132+
<LayInput v-model={model.password}></LayInput>
133+
</LayFormItem>
134+
</LayForm>
135+
);
136+
},
137+
});
138+
139+
return wrapper;
140+
}
141+
142+
test("单个 required form-item是否触发校验", async () => {
143+
const wrapper = createForm();
144+
145+
const formComponent = wrapper.findComponent(LayForm);
146+
147+
const fn = vi.fn();
148+
149+
formComponent.vm.validate(fn);
150+
await sleep(300);
151+
152+
expect(fn).toHaveBeenCalled();
153+
expect(fn.mock.calls[0][0]).toBeFalsy();
154+
});
155+
});
116156
});

packages/component/component/formItem/index.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ const validate = (
177177
clearValidate();
178178
}
179179
});
180+
} else {
181+
resolve(undefined);
180182
}
181183
});
182184
};

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy