简体   繁体   English

在执行 nbStepperNext 之前验证 NbStepperComponent 中的表单

[英]Validate form in NbStepperComponent before executing nbStepperNext

I'm working with nebular's NbStepperComponent in Angular 2 , so far it works fine, only that when I go to the next step I want to perform a previous validation from in a function and just execute nbStepperNext but I don't know how to execute the nbStepperNext from a function , since its documentation It does it directly from the HTML like this <button nbButton nbStepperNext> next </button> I'm working with nebular's NbStepperComponent in Angular 2 , so far it works fine, only that when I go to the next step I want to perform a previous validation from in a function and just execute nbStepperNext but I don't know how to execute来自nbStepperNextfunction ,因为它的文档 它直接从 HTML 像这样<button nbButton nbStepperNext> next </button>

I would like: "Execute the nbStepperNext from a function"我想:“从函数执行nbStepperNext

something like that, but I don't know the correct syntax:类似的东西,但我不知道正确的语法:

<button (click)="validacion()" type="button">Next</button>

validacion(){
//códe validation
       stepper.next(); // and next step
}

My base code我的基本代码

import { Component } from '@angular/core';

    @Component({
      selector: 'nb-stepper-test',
      template: `
        <nb-stepper>
          <nb-step>
            <ng-template nbStepLabel>First step</ng-template>
            <div class="step-container">
              <h3>Información personal</h3>
<div class="row">
        <div class="col-sm-4">
            <div class="form-group">
                <label for="nombre" style="width: 100%;" class="label">First Name</label>
                <input  type="text" nbInput id="nombre" fieldSize="small"  formControlName="nombre" fullWidth>
            </div>
        </div>
        <div class="col-sm-4">
            <label for="paterno" class="label">Last Name</label>
            <input type="text" nbInput id="paterno" fieldSize="small" formControlName="paterno" fullWidth>
        </div>
        <div class="col-sm-4">
            <label for="correo" class="label">Correo</label>
            <input type="text" nbInput id="correo" fieldSize="small" formControlName="correo"  fullWidth>
        </div>
</div>
              <button class="btn btn-primary" disabled nbStepperNext>prev</button>
              <button class="btn btn-primary" nbStepperNext>next</button>
            </div>
          </nb-step>
          <nb-step>
            <ng-template nbStepLabel>Second step</ng-template>
            <div class="step-container">
              <h3>Step content #2</h3>
              <button class="btn btn-primary" nbStepperPrevious>prev</button>
              <button class="btn btn-primary" nbStepperNext>next</button>
            </div>
          </nb-step>
          <nb-step label="Third step">
            <div class="step-container">
              <h3>Step content #3</h3>
              <button class="btn btn-primary" nbStepperPrevious>prev</button>
              <button class="btn btn-primary" nbStepperNext>next</button>
            </div>
          </nb-step>
          <nb-step>
            <ng-template nbStepLabel>Fourth step</ng-template>
            <div class="step-container">
              <h3>Step content #4</h3>
              <button class="btn btn-primary" nbStepperPrevious>prev</button>
              <button class="btn btn-primary" disabled nbStepperNext>next</button>
            </div>
          </nb-step>
        </nb-stepper>
      `,
    })
    export class StepperTestComponent {
    }

According to the documentation, next() and previous() are part of NbStepperComponent .根据文档, next()previous()NbStepperComponent的一部分。 Therefor, your solution should be:因此,您的解决方案应该是:

@Component({
    selector: 'nb-stepper-test',
    template: `
        <nb-stepper #stepper>
          <nb-step>
            ...
          </nb-step>
          <nb-step>
            ...
          </nb-step>
          <nb-step>
            ...
          </nb-step>
        </nb-stepper>
      `,
})
export class StepperTestComponent {
    @ViewChild('stepper') stepper: NbStepperComponent;

    validacion() {
        // Form validation goes here...
        this.stepper.next();
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM