Skip to content
Snippets Groups Projects
Commit b3e870b5 authored by rhenck's avatar rhenck
Browse files

Fix radio-button-group sanitization

Transform string array to Textlabel array.

#338
parent c18fb2ed
No related branches found
No related tags found
No related merge requests found
...@@ -8,7 +8,7 @@ import { Unit } from 'common/models/unit'; ...@@ -8,7 +8,7 @@ import { Unit } from 'common/models/unit';
import { import {
BasicStyles, DragNDropValueObject, ExtendedStyles, BasicStyles, DragNDropValueObject, ExtendedStyles,
InputElement, PlayerProperties, InputElement, PlayerProperties,
PositionedUIElement, PositionProperties, TextImageLabel, PositionedUIElement, PositionProperties, TextImageLabel, TextLabel,
UIElement, UIElementValue UIElement, UIElementValue
} from 'common/models/elements/element'; } from 'common/models/elements/element';
import { LikertElement } from 'common/models/elements/compound-elements/likert/likert'; import { LikertElement } from 'common/models/elements/compound-elements/likert/likert';
...@@ -27,6 +27,7 @@ import { Section } from 'common/models/section'; ...@@ -27,6 +27,7 @@ import { Section } from 'common/models/section';
import { IDManager } from 'common/util/id-manager'; import { IDManager } from 'common/util/id-manager';
import { RadioButtonGroupComplexElement } from 'common/models/elements/input-elements/radio-button-group-complex'; import { RadioButtonGroupComplexElement } from 'common/models/elements/input-elements/radio-button-group-complex';
import packageJSON from '../../../package.json'; import packageJSON from '../../../package.json';
import { RadioButtonGroupElement } from 'common/models/elements/input-elements/radio-button-group';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
...@@ -116,6 +117,9 @@ export class SanitizationService { ...@@ -116,6 +117,9 @@ export class SanitizationService {
.includes(newElement.type as string)) { .includes(newElement.type as string)) {
newElement = SanitizationService.handlePlusOne(newElement as InputElement); newElement = SanitizationService.handlePlusOne(newElement as InputElement);
} }
if (['radio'].includes(newElement.type as string)) {
newElement = SanitizationService.handleRadioGroup(newElement as RadioButtonGroupElement);
}
if (['radio-group-images'].includes(newElement.type as string)) { if (['radio-group-images'].includes(newElement.type as string)) {
newElement = SanitizationService.fixImageLabel(newElement as RadioButtonGroupComplexElement); newElement = SanitizationService.fixImageLabel(newElement as RadioButtonGroupComplexElement);
} }
...@@ -419,7 +423,7 @@ export class SanitizationService { ...@@ -419,7 +423,7 @@ export class SanitizationService {
return element as ToggleButtonElement; return element as ToggleButtonElement;
} }
private static fixImageLabel(element: Partial<RadioButtonGroupComplexElement>) { private static fixImageLabel(element: Partial<RadioButtonGroupComplexElement>): RadioButtonGroupComplexElement {
return { return {
...element, ...element,
options: element.options ? options: element.options ?
...@@ -428,6 +432,18 @@ export class SanitizationService { ...@@ -428,6 +432,18 @@ export class SanitizationService {
.map((column: TextImageLabel) => ({ .map((column: TextImageLabel) => ({
...column, imgPosition: column.imgPosition || (column as any).position || 'above' ...column, imgPosition: column.imgPosition || (column as any).position || 'above'
})) }))
}; } as RadioButtonGroupComplexElement;
}
private static handleRadioGroup(element: Partial<RadioButtonGroupElement>): RadioButtonGroupElement {
return {
...element,
options: element.options ?
element.options :
(element.richTextOptions as string[])
.map((option: string) => ({
text: option
}))
} as RadioButtonGroupElement;
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment