Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input field validations #85

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from './grid-layout.model'
// tslint:disable-next-line
import _ from 'lodash'
import { MatSnackBar } from '@angular/material'

const API_END_POINTS = {
fetchProfileById: (id: string) => `/apis/proxies/v8/api/user/v2/read/${id}`,
Expand All @@ -34,6 +35,7 @@ export class GridLayoutComponent extends WidgetBaseComponent
private configSvc: ConfigurationsService,
private http: HttpClient,
private npsService: NPSGridService,
private snackBar: MatSnackBar,
) {
super()
}
Expand Down Expand Up @@ -117,6 +119,7 @@ export class GridLayoutComponent extends WidgetBaseComponent
isMobile = false
reviewCommentLength = 0
@ViewChild('textArea', { static: false }) textArea!: ElementRef
noHtmlCharacter = new RegExp(/<[^>]*>|(function[^\s]+)|(javascript:[^\s]+)/i)
ngOnInit() {
this.npsCategory = localStorage.getItem('npsCategory') ? localStorage.getItem('npsCategory') : 'NPS'
if (window.innerWidth < 540) {
Expand Down Expand Up @@ -523,9 +526,21 @@ export class GridLayoutComponent extends WidgetBaseComponent
)
}

private openSnackbar(primaryMsg: string, duration: number = 2000) {
this.snackBar.open(primaryMsg, 'X', {
duration,
})
}

getReviewCommentLength() {
if (this.textArea && this.textArea.nativeElement && this.textArea.nativeElement.value) {
this.reviewCommentLength = this.textArea.nativeElement.value.length
if (this.textArea.nativeElement.value.match(this.noHtmlCharacter)) {
this.submitBtnClick = true
this.openSnackbar('HTML or Js is not allowed')
} else {
this.submitBtnClick = false
}
} else {
this.reviewCommentLength = 0
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import { NgModule } from '@angular/core'
import { CommonModule } from '@angular/common'
import { GridLayoutComponent } from './grid-layout.component'
import { WidgetResolverModule } from '@sunbird-cb/resolver'
import { MatButtonModule, MatFormFieldModule, MatIconModule } from '@angular/material'
import { MatButtonModule, MatFormFieldModule, MatIconModule, MatSnackBarModule } from '@angular/material'
import { FormsModule } from '@angular/forms'
import { NPSGridService } from './nps-grid.service'
import { TranslateModule } from '@ngx-translate/core'

@NgModule({
declarations: [GridLayoutComponent],
imports: [CommonModule, WidgetResolverModule, MatFormFieldModule, MatButtonModule, MatIconModule, FormsModule, TranslateModule],
imports: [CommonModule, WidgetResolverModule, MatFormFieldModule,
MatButtonModule, MatIconModule, FormsModule, TranslateModule, MatSnackBarModule],
exports: [GridLayoutComponent],
entryComponents: [GridLayoutComponent],
providers: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@
</div> -->
<div class="flex flex-row gap-4 items-center edit-name" *ngIf="editName">
<!-- pattern="/^[a-z0-9._-]+$/i" -->
<input #profileNameVar="ngModel" type="text" name="profileNameVar" [(ngModel)]="profileName" class="input-text"/>
<input #profileNameVar="ngModel" type="text" name="profileNameVar" [(ngModel)]="profileName" class="input-text" (input)="validateName($event.target.value)"/>
<!-- <div
*ngIf="profileNameVar.invalid && (profileNameVar.dirty || profileNameVar.touched)"
class="alert"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ export class ProfileViewComponent implements OnInit, AfterViewInit, OnDestroy {
showBatchForNoCadre = true
noCadreDetails = true
saveChanges = false
noHtmlCharacter = new RegExp(/<[^>]*>|(function[^\s]+)|(javascript:[^\s]+)/i)
constructor(
public dialog: MatDialog,
private configService: ConfigurationsService,
Expand Down Expand Up @@ -1348,6 +1349,13 @@ export class ProfileViewComponent implements OnInit, AfterViewInit, OnDestroy {
}

handleUpdateName(): void {

const regexMatch = this.profileName.match(this.noHtmlCharacter)
if (regexMatch) {
this.matSnackBar.open('HTML or Js is not allowed')
return
}

const postData = {
'request': {
'userId': this.configService.unMappedUser.id,
Expand Down