如果验证失败,如何停止Metronic向导

时间:2019-12-15 07:31:12

标签: angular metronic

即使出现错误,也可以导航到下一步。下面是我的代码。请帮助

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);
        }
    });

2 个答案:

答案 0 :(得分:2)

还有另一种方式

// Validation before going to next page
wizard.on("beforeNext", wizardObj => {
  if (wizardObj.currentStep === 1) {
    if (this.form.invalid) {
      this.form.markAllAsTouched();
      wizardObj.stop();
    }
  }
});

答案 1 :(得分:0)

可能已经晚了,但这应该可以工作:

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

检索当前步骤:

step = wizardObj.getStep();

转到特定步骤:

wizardObj.goTo(step);