Skip to content
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 @@ -5,16 +5,14 @@
[class.content-matrix]="isMatrix"
>
<div class="header" dir="auto">
<p *ngIf="!isSectionHeaderHidden">{{ question.section_header }}</p>
<p *ngIf="!isSectionHeaderHidden" [innerHTML]="sanitizedSectionHeader"></p>
<div
*ngIf="!isFieldLabelHidden"
class="field-container"
[class.field-container-matrix]="isMatrix"
dir="auto"
>
<h2 dir="auto">
{{ question.field_label }}
</h2>
<h2 dir="auto" [innerHTML]="sanitizedFieldLabel"></h2>
</div>
</div>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import {
OnChanges,
OnInit,
Output,
SecurityContext,
ViewChild
} from '@angular/core'
import { DomSanitizer } from '@angular/platform-browser'

import {
KeyboardEventType,
Expand Down Expand Up @@ -49,6 +51,8 @@ export class QuestionComponent implements OnInit, OnChanges {
@Output()
nextAction: EventEmitter<any> = new EventEmitter<any>()

sanitizedSectionHeader = ''
sanitizedFieldLabel = ''
value: any
currentlyShown = false
previouslyShown = false
Expand Down Expand Up @@ -97,11 +101,12 @@ export class QuestionComponent implements OnInit, OnChanges {
QuestionType.checkbox
])

constructor() {
constructor(private sanitizer: DomSanitizer) {
this.value = null
}

ngOnInit() {
this.updateSanitizedHtml()
this.isScrollable = !this.NON_SCROLLABLE_SET.has(this.question.field_type)
this.isFieldLabelHidden = this.HIDE_FIELD_LABEL_SET.has(
this.question.field_type
Expand Down Expand Up @@ -131,6 +136,15 @@ export class QuestionComponent implements OnInit, OnChanges {
}
}

private sanitizeHtml(value: string): string {
return this.sanitizer.sanitize(SecurityContext.HTML, value || '') || ''
}

private updateSanitizedHtml() {
this.sanitizedSectionHeader = this.sanitizeHtml(this.question?.section_header)
this.sanitizedFieldLabel = this.sanitizeHtml(this.question?.field_label)
}

emitAnswer(event: any) {
// Only proceed if event is not null or undefined
if (event !== null && event !== undefined) {
Expand Down
Loading