Johann-S / bs-stepper

A stepper for Bootstrap 4.x
https://johann-s.github.io/bs-stepper/
MIT License
447 stars 88 forks source link

Cannot read properties of null (reading 'classList') at bs-stepper.js:265:17 #314

Closed adrian-badulescu closed 1 year ago

adrian-badulescu commented 1 year ago

I am trying to implement this library to an angular project as per this StackBlitz example https://stackblitz.com/edit/bs-stepper-angular?file=src%2Fapp%2Fapp.component.ts but I am getting this error.

I mention that I am using the npm package

My implementation: controller.ts `` import { Component, OnDestroy, OnInit } from '@angular/core'; import { FormBuilder, FormControl, FormArray, FormGroup } from '@angular/forms'; import { IContactForm } from '../interfaces/contactForm'; import { Validators } from '@angular/forms'; import { debounceTime, distinctUntilChanged, filter, fromEvent, map, switchMap, tap, catchError, of, retry, Observable, Subscription, iif, finalize, Subject, BehaviorSubject } from 'rxjs';

import { BackendService } from 'app/services/backend/backend.service'; import { SpinnerService } from 'app/services/spinner/spinner.service'; import { ActivatedRoute } from '@angular/router'; import Stepper from 'bs-stepper';

@Component({ selector: 'app-order-form', templateUrl: './order-form.component.html', styleUrls: ['./order-form.component.css'] })

export class OrderFormComponent implements OnInit, OnDestroy {

contactForm: FormGroup;
domainSearchResult?: boolean; showContactFrom: boolean = false; submitted = false; searchingSpinner?: boolean = false; keyClicksSubscription: Subscription = new Subscription(); routeParamsSubscription: Subscription = new Subscription(); displaySpinner: BehaviorSubject = this._spinnerService.spinnerBooleanState; templateTitle: string = ''; templateId: string = ''; private stepper!: Stepper;

constructor(private _fb: FormBuilder, private _backendService: BackendService, private _spinnerService: SpinnerService, private route: ActivatedRoute) { this.contactForm = this._fb.group({ webdomain: [null,[Validators.pattern]], contactForm: this._fb.group({ surname: [null, [Validators.required]], firstname: [null, [Validators.required]], email: [null, [Validators.required]], phone: [null] }) }); }

get surname() {return this.contactForm.controls.contactForm.get('surname')}; get firstname() {return this.contactForm.controls.contactForm.get('firstname')}; get email() {return this.contactForm.controls.contactForm.get('email')}; get phone() {return this.contactForm.controls.contactForm.get('phone')};

onSubmit() { this.submitted = true; // TODO: Use EventEmitter with form value console.log(this.contactForm.value);
}

keyClicks(): Observable { const searchBox = document.getElementById('webdomain') as HTMLInputElement; const keyboardInput = fromEvent(searchBox, 'input').pipe( map(e => (e.target as HTMLInputElement).value), filter(text => text.length > 4), debounceTime(2000), distinctUntilChanged(), switchMap(searchTerm => this._backendService.searchDomain(searchTerm)) ) .pipe( // tap(httpQueryResultAsBoolean => this.addContactFields(httpQueryResultAsBoolean)) ) return keyboardInput; }

nextStep() { this.stepper.next(); }

ngOnInit(): void { this.keyClicksSubscription = this.keyClicks().subscribe(KeyboardEvent => this.domainSearchResult = KeyboardEvent); this.routeParamsSubscription = this.route.queryParams .subscribe(params => { this.templateTitle = params.order; this.templateId = params.Id; console.log(Template Title: ${this.templateTitle} - Template Id: ${this.templateId}); // popular }); this.stepper = new Stepper(document.querySelector('#stepper1'), { linear: false, animation: true }) }

ngOnDestroy(): void { this.keyClicksSubscription.unsubscribe(); this.routeParamsSubscription.unsubscribe(); }

} ``

component.html ``

Câmpul Nume este necesar
Câmpul Prenume este necesar
                </div>
                <div class="mb-3">
                    <label class="form-label">E-mail*</label>
                    <input type="text" formControlName="email" class="form-control"
                        [ngClass]="{ 'is-invalid': submitted && email?.errors }" />
                    <div *ngIf="submitted && email?.errors" class="invalid-feedback">
                        <div *ngIf="email?.errors?.required">Câmpul <b>E-mail</b> este necesar</div>
                    </div>
                </div>
                <div class="mb-3">
                    <label class="form-label">Telefon</label>
                    <input type="text" formControlName="phone" class="form-control"
                        [ngClass]="{ 'is-invalid': submitted && phone?.errors }" />
                    <div *ngIf="submitted && phone?.errors" class="invalid-feedback">
                        <div *ngIf="phone?.errors?.required">Password is required</div>
                    </div>
                </div> 
            </ng-container>
            <button  type="submit" class="btn btn-primary">Submit</button>
        </div>                
    </form>  
  </div>
</div>

package.json { "name": "newtd", "version": "0.0.0", "scripts": { "ng": "ng", "prestart": "node aspnetcore-https", "start": "run-script-os", "start:windows": "ng serve --port 44417 --ssl --ssl-cert %APPDATA%\ASP.NET\https\%npm_package_name%.pem --ssl-key %APPDATA%\ASP.NET\https\%npm_package_name%.key", "start:default": "ng serve --port 44417 --ssl --ssl-cert $HOME/.aspnet/https/${npm_package_name}.pem --ssl-key $HOME/.aspnet/https/${npm_package_name}.key", "build": "ng build", "build:ssr": "ng run newTD:server:dev", "watch": "ng build --watch --configuration development", "test": "ng test" }, "private": true, "dependencies": { "@angular/common": "^14.0.3", "@angular/compiler": "^14.0.3", "@angular/core": "^14.0.3", "@angular/forms": "^14.0.3", "@angular/localize": "^14.0.3", "@angular/platform-browser": "^14.0.3", "@angular/platform-browser-dynamic": "^14.0.3", "@angular/platform-server": "^14.0.3", "@angular/router": "^14.0.3", "@ng-bootstrap/ng-bootstrap": "^13.0.0", "@nguniversal/module-map-ngfactory-loader": "^8.2.6", "@popperjs/core": "^2.11.7", "bootstrap": "^5.2.3", "bs-stepper": "^1.7.0", "ng-recaptcha": "^10.0.0", "oidc-client": "^1.11.5", "popper.js": "^1.16.0", "run-script-os": "^1.1.6", "rxjs": "~7.5.5", "tslib": "^2.4.0", "zone.js": "~0.11.6" }, "devDependencies": { "@angular-devkit/build-angular": "^14.0.3", "@angular/cli": "^14.0.3", "@angular/compiler-cli": "^14.0.3", "@types/jasmine": "~4.0.3", "@types/jasminewd2": "~2.0.10", "@types/node": "^18.0.0", "jasmine-core": "~4.2.0", "karma": "~6.4.0", "karma-chrome-launcher": "~3.1.1", "karma-coverage": "~2.2.0", "karma-jasmine": "~5.1.0", "karma-jasmine-html-reporter": "^2.0.0", "typescript": "~4.7.4" }, "overrides": { "autoprefixer": "10.4.5" } }

``

Please let me know if you need any other iformation from my side.

Thank you!