angular material stepper: disable header navigation

后端 未结 11 971
再見小時候
再見小時候 2021-02-03 18:16

I want to navigate the stepper only through the next and back buttons.

I can\'t get this to work since users can also click each step label to navigate to any step. I c

11条回答
  •  鱼传尺愫
    2021-02-03 19:01

    I found a somewhat hacky solution for this. The problem is that you cannot fully disable the header navigation, but you can prevent it from being active until a certain moment.

    And that moment is form.invalid.

    My situation was the following: User needs to fill the form inside the step, press 'save' and only then be able to use NEXT button and navigate the stepper further (also back).

    What I did was introduce another hidden input which would be using angular's [required] dynamic attribute. It will only be required if the previous save condition wasn't successful. Once it succeeds this field won't be required and user can navigate further.

    Together with mat-stepper (or md-stepper) attribute editable you should be able to achieve what you want.

    Let me know if you fully understood the idea.

提交回复
热议问题