title: Angular: Making Button Toggle Group required for Material Stepper
body: <p>I'm relatively new to Angular and am just getting to grips with the Material Design Components and how they work and can interact with each other. </p>
  
  <p>I'm building a multi-step web application, so it seemed logical to use the Material Stepper. The user will also be able to choose between various options on these steps, so I've used the Button Toggle Group to present these options.</p>
  
  <p>What I'd like to be able to do - and am wondering if it is possible - is to make the Button Toggle Group a "required" field for the stepper. On some instances, the toggle group will be the only option on the step and I'd like to make it so that the user can't move onto the next step without selecting a Toggle Group option.</p>
  
  <p>I've tried simple solutions like adding "required" onto the mat-button-toggle, like so:</p>
  
  <pre><code>&lt;mat-button-toggle (click)="getOptionName(Oname);" class="btn btn-primary step-button" id="{{step1option.id}}" [ngClass]="status ? 'selected' : ''" required&gt;&lt;span #Oname&gt;{{step1option.text}}&lt;/span&gt;&lt;/mat-button-toggle&gt;
  </code></pre>
  
  <p>And onto the mat-button-toggle-group:</p>
  
  <pre><code>&lt;mat-button-toggle-group required&gt;
  </code></pre>
  
  <p>But, unfortunately it's not that simple, which I didn't expect it to be. But hey, you might as well start with the most simple and obvious solution first, right?</p>
  
  <p>Obviously, it didn't work and my knowledge of Angular isn't that extensive at the moment and trying various searches didn't turn up anything helpful (and/or anything I could understand).</p>
  
  <p>Here's my code so far:</p>
  
  <p>My component.html: </p>
  
  <pre><code>&lt;mat-horizontal-stepper [linear]="isLinear" #stepper&gt;
      &lt;mat-step label="Step 1" [stepControl]="firstFormGroup"&gt;
  
          &lt;form [formGroup]="firstFormGroup"&gt;
  
          &lt;div ng-controller="step1"&gt;
  
              &lt;h2&gt;I'm thinking of...&lt;/h2&gt;
  
              &lt;mat-button-toggle-group&gt;
                &lt;div *ngFor="let step1option of step1options"&gt;
                  &lt;mat-button-toggle (click)="getOptionName(Oname);" class="btn btn-primary step-button" id="{{step1option.id}}" [ngClass]="status ? 'selected' : ''"&gt;&lt;span #Oname&gt;{{step1option.text}}&lt;/span&gt;&lt;/mat-button-toggle&gt;
                &lt;/div&gt;
                &lt;/mat-button-toggle-group&gt;
  
              &lt;div&gt;You chose &lt;strong&gt;{{ selectedStep1Option }}!&lt;/strong&gt;&lt;/div&gt;
  
              &lt;button mat-stroked-button matStepperNext class="btn btn-secondary continue-btn"&gt;Continue&lt;/button&gt;
  
           &lt;/div&gt;
  
            &lt;/form&gt;
  
          &lt;/mat-step&gt;
  
          &lt;mat-step label="Step 2" [stepControl]="secondFormGroup"&gt;
              &lt;form [formGroup]="secondFormGroup"&gt;
                &lt;p&gt;Test&lt;/p&gt;
              &lt;/form&gt;
          &lt;/mat-step&gt;
  
          &lt;mat-step label="Step 3" [stepControl]="thirdFormGroup"&gt;
              &lt;form [formGroup]="thirdFormGroup"&gt;
                &lt;p&gt;Test&lt;/p&gt;
              &lt;/form&gt;
          &lt;/mat-step&gt;
  
  &lt;/mat-horizontal-stepper&gt;
  </code></pre>
  
  <p>And my component.ts:</p>
  
  <pre><code>import { Component, OnInit } from '@angular/core';
  import { TimeoutError } from 'rxjs';
  import {FormBuilder, FormGroup, Validators} from '@angular/forms';
  
  @Component({
    selector: 'app-customer-portal-step1',
    templateUrl: './customer-portal-step1.component.html',
    styleUrls: ['./customer-portal-step1.component.scss']
  })
  
  export class CustomerPortalStepOneComponent implements OnInit {
  
    isLinear = true;
    firstFormGroup: FormGroup;
    secondFormGroup: FormGroup;
    thirdFormGroup: FormGroup;
  
    constructor(private _formBuilder: FormBuilder) { }
  
    ngOnInit() {
      this.firstFormGroup = this._formBuilder.group({
        firstCtrl: ['', Validators.required]
      });
      this.secondFormGroup = this._formBuilder.group({
        secondCtrl: ['', Validators.required]
      });
      this.thirdFormGroup = this._formBuilder.group({
        secondCtrl: ['', Validators.required]
      });
    }
  
    selectedStep1Option: string = 'nothing yet';
  
    step1options = [
      {
        text: 'Buying my first home',
        id: 'buying'
      },
      {
        text: 'Moving to a new home',
        id: 'moving'
      },
      {
        text: 'Remortgaging my home',
        id: 'remortgage'
      },
      {
        text: 'Purchasing a buy-to-let',
        id: 'purchase'
      }
    ];
  
    status: boolean = false;
  
    getOptionName (Oname: any) {
      this.selectedStep1Option = Oname.textContent;
      localStorage.setItem('I\'m thinking of:', JSON.stringify({ motivation: Oname.textContent }));
    }
  
  }
  </code></pre>
  
  <p>I guess what I'm asking is, is this even possible, am I on the right track and, if not, what's the best approach for me to get the result I'm hoping for?</p>
  
  <p>Any help you can offer would be appreciated.</p>