I have a site in Angular 14. Registration button is working fine in desktop, but not working in mobile. Wierd thing is, when I press the Create Account button without filling the signup form, then the button works and gives me validation messages like "First Name Is Missing" and so on. But when I fill up the form fully and then press Create Account button, it do nothing in mobile. Tested on Safari and Chrome browser, on both it does nothing.
Component.html code
<form [formGroup]="fg" (ngSubmit)="save(fg)" #f="ngForm">
<input type="hidden" formControlName="id">
<div class="form-group login-input">
<label for="Firstname"><i class="zmdi zmdi-account material-icons-name p-3"></i></label>
<input type="text" formControlName="first_name" class="form-control" name="first_name" id="Firstname" placeholder="First Name" required="" control-id="ControlID-2">
<div *ngIf="fh.check(g['first_name'], f)" class="errors">
<p *ngIf="g['first_name'].errors">First name is required</p>
</div>
</div>
<div class="form-group login-input">
<label for="Lastname"><i class="zmdi zmdi-account material-icons-name p-3"></i></label>
<input type="text" formControlName="last_name" class="form-control" name="lastname" id="Lastname" placeholder="Last Name" required="" control-id="ControlID-3">
<div *ngIf="fh.check(g['last_name'], f)" class="errors">
<p *ngIf="g['last_name'].errors">Last name is required</p>
</div>
</div>
<div class="form-group login-input">
<label for="mobilenumber " class="numberfixdigite">
+61
</label>
<input type="text" oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*?)\..*/g, '$1');" formControlName="phone_number" class="form-control" minlength="9" maxlength="12" name="phone" id="mobilenumber" placeholder="Phone number" required="" control-id="ControlID-4">
<span style="color:red">Please enter mobile like 4xx 8xx 5xx</span>
<div *ngIf="fh.check(g['phone_number'], f)" class="errors">
<p *ngIf="g['phone_number'].errors">Mobile is required</p>
</div>
</div>
<div class="form-group login-input">
<label for="email"><i class="zmdi zmdi-email p-3"></i></label>
<input type="email" formControlName="email" name="email" class="form-control" id="email" placeholder="Email" required="" control-id="ControlID-5">
<div *ngIf="fh.check(g['email'], f)" class="errors">
<p *ngIf="g['email'].errors">Email is required</p>
</div>
</div>
<div class="form-group login-input">
<label for="label-183"><i class="zmdi zmdi-pin p-3"></i></label>
<input type="text" autocomplete="off" formControlName="postcode" spellcheck="false" class=" form-control TextInput__StyledInput-sc-8dpq00-1 dvowrP typeahead__input" data-ui-test="location-input" name="suburb" placeholder="Suburb or Postcode" id="label-183" value="" required="" control-id="ControlID-6"
matInput
matGoogleMapsAutocomplete
(onAutocompleteSelected)="onAutocompleteSelected($event)"
(onLocationSelected)="onLocationSelected($event)"
>
<div *ngIf="fh.check(g['postcode'], f)" class="errors">
<p *ngIf="g['postcode'].errors">Postcode is required</p>
</div>
</div>
<div class="form-group login-input">
<label for="state"><i class="zmdi zmdi-city p-3"></i></label>
<input type="dropdown" formControlName="state" class="form-control" name="state" id="state" placeholder="State" required="" control-id="ControlID-7">
<div *ngIf="fh.check(g['state'], f)" class="errors">
<p *ngIf="g['state'].errors">State is required</p>
</div>
</div>
<div class="form-group login-input">
<label for="pass"><i class="zmdi zmdi-lock p-3"></i></label>
<input type="password" formControlName="password" class="form-control" name="password" id="pass" placeholder="Create Password" required="" control-id="ControlID-8">
<div *ngIf="fh.check(g['password'], f)" class="errors">
<p *ngIf="g['password'].errors">Password is required</p>
</div>
</div>
<div class="form-group form-button mb-1">
<div class="form-group form-button mb-1">
<button type="submit" class="btn btn-primary btn-group-vertical buttonweb" control-id="ControlID-9">
<span class="text-white"> Create Account</span>
</button>
</div>
</div>
<span class="social-label">or continue with</span>
<div class="social-login">
<ul class="socials m-auto">
<li><a (click)="signInWithFB()" target="_blank"><i class="display-flex-center zmdi zmdi-facebook"></i></a></li>
<li><a #loginRef><i class="display-flex-center zmdi zmdi-google"></i></a></li>
</ul>
</div>
<div class="d-flex">
<br>
<p class="Text__StyledTypographyComponent-sc-35e02v-0 bfXubR ">By signing up, I agree to JobTasker's <a href="/terms-conditions" target="_blank" rel="noreferrer">Terms & Conditions</a>, <a href="/guidelines/" target="_blank" rel="noreferrer">Community Guidelines</a> & <a href="/privacy-policy" target="_blank" rel="noopener noreferrer">Privacy Policy</a>. </p>
</div>
</form>
component.td code
import { ApiService } from './../../servies/api.service';
import { googleLogin } from './../../../environments/environment';
import { FormHelper } from './../../shared/FormHelper';
import { Component, ElementRef, OnInit, ViewChild } from '@angular/core';
import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
import { DataService } from './data.service';
import { ToastrService } from 'ngx-toastr';
import { ActivatedRoute, Router } from '@angular/router';
import { getMessaging, getToken, onMessage } from "firebase/messaging";
import { environment, firebaseConfig } from 'src/environments/environment.prod';
import {
FacebookLoginProvider,
GoogleLoginProvider,
SocialAuthService,
} from '@abacritt/angularx-social-login';
import {Location, Appearance, GermanAddress} from '@angular-material-extensions/google-maps-autocomplete';
import PlaceResult = google.maps.places.PlaceResult;
// import {Location, Appearance, GermanAddress} from '@angular-material-extensions/google-maps-autocomplete';
// import geocoder = google.maps.Geocoder;
@Component({
selector: 'app-register',
templateUrl: './register.component.html',
styleUrls: ['./register.component.scss'],
providers: [DataService]
})
export class RegisterComponent implements OnInit {
auth2: any;
@ViewChild('loginRef', { static: true }) loginElement!: ElementRef;
public fg: FormGroup;
type: string;
public appearance = Appearance;
public zoom: number = 10;
public latitude: number = 0;
public longitude: number = 0;
public place_id: any = '';
public plase_url: any = '';
mapdata = false;
onAutocompleteSelected(result: PlaceResult) {
this.mapdata = true;
//console.log(result.url, result);
this.place_id = result.place_id;
this.plase_url = result.url;
}
onLocationSelected(location: Location) {
//console.log('onLocationSelected: ', location);
this.latitude = location.latitude;
this.longitude = location.longitude;
}
onGermanAddressMapped($event: GermanAddress) {
//console.log('onGermanAddressMapped', $event);
}
// Google Map Apis Function
private setCurrentPosition() {
if ('geolocation' in navigator) {
navigator.geolocation.getCurrentPosition((position) => {
console.log('position', position);
});
}
}
constructor(public fb: FormBuilder,
private route: ActivatedRoute,
public fh: FormHelper,
private api: DataService,
private apii: ApiService,
public router: Router,
private ts: ToastrService,
private authService: SocialAuthService,) {
this.type = String(this.route.snapshot.paramMap.get('type'));
this.fg = this.fb.group({
id: new FormControl(-1, []),
email: new FormControl(null, [Validators.required, Validators.email]),
first_name: new FormControl('', [Validators.required]),
last_name: new FormControl(null, [Validators.required]),
phone_number: new FormControl(null, [Validators.required, Validators.pattern('')]),
postcode: new FormControl(null, [Validators.required]),
state: new FormControl(null, [Validators.required]),
//abn: new FormControl(null, [Validators.required]),
password: new FormControl(null, [Validators.required]),
password_confirmation: new FormControl(null, []),
agreeterm: new FormControl(false, [Validators.required]),
user_type: this.type
});
}
public get g() {
return this.fg.controls;
}
ngOnInit() {
this.googleAuthSDK();
this.setCurrentPosition();
}
listen() {
const messaging = getMessaging();
onMessage(messaging, (payload) => {
console.log('Message received. ', payload);
});
}
public save(data: any): boolean {
const messaging = getMessaging();
console.log(data.value);
this.fg.patchValue({ password_confirmation: data.value.password });
if (data.status === 'INVALID') {
this.ts.warning('There is validation issue kindly review the form again!!');
return false;
}
getToken(messaging,
{ vapidKey: firebaseConfig.vapidKey }).then(
(currentToken) => {
if (currentToken) {
console.log(currentToken);
let dataT = data.value;
let temp = { ...dataT, fcm_token: currentToken,
lat : this.latitude,
lng : this.longitude,
place_id : this.place_id,
place_url : this.plase_url
}
console.log(temp);
let saveMethod = this.api.save(temp);
if (data.value.id > 0) {
saveMethod = this.api.update(temp);
}
saveMethod.subscribe((resp: any) => {
if (resp.success === false) {
this.ts.error(resp.message);
return false;
} else {
console.log(resp);
if (data.value.id > 0) {
// this.api.updateItem(resp.data.result, -1);
this.ts.success('Registered successfully!!');
} else {
data.value.id = resp.data.id;
// this.api.addItem(resp.data.result);
this.ts.success('Registered successfully!!');
}
this.router.navigate(['/login']);
return true;
}
});
} else {
console.log('No registration token available. Request permission to generate one.');
}
}).catch((err) => {
console.log('An error occurred while retrieving token. ', err);
});
return false;
return false;
}
callLoginButton() {
this.auth2.attachClickHandler(this.loginElement.nativeElement, {},
(googleAuthUser: any) => {
let profile = googleAuthUser.getBasicProfile();
//console.log('Token || ' + googleAuthUser.getAuthResponse().id_token);
// console.log('ID: ' + profile.getId());
// console.log('Name: ' + profile.getName());
// console.log('Image URL: ' + profile.getImageUrl());
// console.log('Email: ' + profile.getEmail());
//console.log();
let fullName = profile.getName().split(' ');
this.fg.controls['first_name'].setValue(fullName[0]);
this.fg.controls['last_name'].setValue(fullName[1]);
this.fg.controls['email'].setValue(profile.getEmail());
}, (error: any) => {
console.log(JSON.stringify(error, undefined, 2));
});
}
googleAuthSDK() {
(<any>window)['googleSDKLoaded'] = () => {
(<any>window)['gapi'].load('auth2', () => {
this.auth2 = (<any>window)['gapi'].auth2.init({
client_id: googleLogin.client_id,
cookiepolicy: 'single_host_origin',
plugin_name: 'Web client 1',
scope: 'profile email'
});
this.callLoginButton();
});
}
(function (d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) { return; }
js = d.createElement('script');
js.id = id;
js.src = "https://apis.google.com/js/platform.js?onload=googleSDKLoaded";
fjs?.parentNode?.insertBefore(js, fjs);
}(document, 'script', 'google-jssdk'));
}
// Facebook
signInWithFB(): void {
this.authService.signIn(FacebookLoginProvider.PROVIDER_ID);
}
}
module.ts code
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RegisterComponent } from './register.component';
import { RouterModule } from '@angular/router';
import { SharedModule } from '../../shared/shared.module';
import { ReactiveFormsModule } from '@angular/forms';
import { AgmCoreModule } from '@agm/core';
import { GoogleMapApi } from 'src/environments/environment';
import { MatGoogleMapsAutocompleteModule } from '@angular-material-extensions/google-maps-autocomplete';
@NgModule({
imports: [
AgmCoreModule.forRoot({
apiKey: GoogleMapApi.apikey,
libraries: ['places']
}),
MatGoogleMapsAutocompleteModule,
CommonModule,
SharedModule,
ReactiveFormsModule,
RouterModule.forChild([
{
path: '',
component: RegisterComponent
}
])
],
declarations: [RegisterComponent]
})
export class RegisterModule { }