我正在使用角度为2的Devextreme表格。 我有两个单独的表单,但是当我调用第一个表单或第二个表单的提交按钮时,两个表单都会得到验证。为什么呢?
这是html中的两种不同形式,
<form action="your-action" (submit)="onFormSubmit($event)">
<diav class="dx-fieldset">
<div class="dx-fieldset-header">Credentials</div>
<div class="dx-field">
<div class="dx-field-label">Login</div>
<div class="dx-field-value">
<dx-text-box>
<dx-validator>
<dxi-validation-rule type="required" message="Login is required"></dxi-validation-rule>
</dx-validator>
</dx-text-box>
</div>
</div>
</div>
<dx-validation-summary id="summary"></dx-validation-summary>
<dx-button
id="button"
text="Register"
type="success"
[useSubmitBehavior]="true">
</dx-button>
</form>
<form action="your-action" (submit)="onFormSubmit1($event)">
<div class="dx-fieldset">
<div class="dx-fieldset-header">Credentials</div>
<div class="dx-field">
<div class="dx-field-label">Login</div>
<div class="dx-field-value">
<dx-text-box>
<dx-validator>
<dxi-validation-rule type="required" message="Login is required"></dxi-validation-rule>
</dx-validator>
</dx-text-box>
</div>
</div>
</div>
<dx-validation-summary id="summary"></dx-validation-summary>
<dx-button
id="button"
text="Register"
type="success"
[useSubmitBehavior]="true">
</dx-button>
</form>
答案 0 :(得分:2)
根据文档[useSubmitBehavior]="true"
将验证并提交html表单。您需要设置validation group
以对表单控件进行分组,然后按钮onClick您可以执行DevExpress.validationEngine.validateGroup(group);
来验证您的控件。添加文档链接。