0

即使出现错误,它也会导航到下一步。下面是我的代码。请帮忙

ngAfterViewInit() {
    // Initialize form wizard
    const wizard = new KTWizard(this.el.nativeElement, {
        startStep: 1
    });

    // Validation before going to next page
    wizard.on('beforeNext', function (wizardObj) {

        // validate the form and use below function to stop the wizard's step
        const form = this.addLocationForm as FormGroup;
        if(!form.valid) {
            wizardObj.stop();
            console.log(form.errors);
        }
    });
4

2 回答 2

2

还有另一种方式

// Validation before going to next page
wizard.on("beforeNext", wizardObj => {
  if (wizardObj.currentStep === 1) {
    if (this.form.invalid) {
      this.form.markAllAsTouched();
      wizardObj.stop();
    }
  }
});
于 2020-04-28T08:53:57.003 回答
0

可能为时已晚,但这应该有效:

function (wizardObj) {
    step = wizardObj.getStep();
    const form = this.addLocationForm as FormGroup;
    if(!form.valid) {
        wizardObj.goTo(step);
    }
});

检索当前步骤:

step = wizardObj.getStep();

转到特定步骤:

wizardObj.goTo(step);
于 2020-01-31T10:49:30.347 回答