Skip to content

Commit

Permalink
Fixed #5982 - An Image question doesn't display a validation error wh…
Browse files Browse the repository at this point in the history
…en replacing an existing image and an image upload error occurs (#5993)
  • Loading branch information
tsv2013 authored Oct 28, 2024
1 parent 66528be commit e4e997a
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions packages/survey-creator-core/src/components/question-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,30 @@ import { getLocString } from "../editorLocalization";
require("./question-image.scss");

export class QuestionImageAdornerViewModel extends QuestionAdornerViewModel {
private editorSurveyModel: SurveyModel;
public filePresentationModel: QuestionFileModel;

private initFilePresentationModel(): void {
this.filePresentationModel = Serializer.createClass("file", { name: this.question.name });
const surveyModel = new SurveyModel();
this.filePresentationModel.setSurveyImpl(surveyModel);
this.editorSurveyModel = new SurveyModel();
this.filePresentationModel.setSurveyImpl(this.editorSurveyModel);
this.filePresentationModel.forceIsInputReadOnly = !this.creator.isCanModifyProperty(this.question, "imageLink");
this.filePresentationModel.filePlaceholder = this.placeholderText;
this.filePresentationModel.chooseButtonCaption = this.chooseImageText;
this.filePresentationModel.acceptedTypes = "image/*";
this.filePresentationModel.storeDataAsText = false;
this.filePresentationModel.cssClasses.chooseFileIconId = "icon-choosefile";
surveyModel.onOpenFileChooser.add((s, o: any) => {
this.editorSurveyModel.onOpenFileChooser.add((s, o: any) => {
this.creator.chooseFiles(o.input, o.callback, o.context);
});
surveyModel.onUploadFiles.add((s, o) => {
this.editorSurveyModel.onUploadFiles.add((s, o) => {
const fileToUpload = o.files[0];
if (!!fileToUpload) {
this.isUploading = true;
this.creator.uploadFiles(o.files, this.question, (status, link) => {
this.question.imageLink = link;
o.callback(status, [{ content: link, file: o.files[0] }]);
this.isUploading = false;
}, { element: this.question, elementType: this.question.getType(), propertyName: "imageLink" });
}
});
Expand All @@ -51,14 +54,9 @@ export class QuestionImageAdornerViewModel extends QuestionAdornerViewModel {

chooseFile(model: QuestionImageAdornerViewModel) {
const fileInput = <HTMLInputElement>model.rootElement.getElementsByClassName("svc-choose-file-input")[0];
const context = { element: model.question, elementType: model.question.getType(), propertyName: "imageLink" };
model.creator.chooseFiles(fileInput, (files: File[]) => {
model.isUploading = true;
model.creator.uploadFiles(files, model.surveyElement as QuestionImageModel, (_, link) => {
(<QuestionImageModel>model.surveyElement).imageLink = link;
model.isUploading = false;
}, context);
}, context);
this.editorSurveyModel.chooseFiles(fileInput, (files: File[]) => {
model.filePresentationModel.loadFiles(files);
});
}
public get acceptedTypes(): string {
return getAcceptedTypesByContentMode((this.surveyElement as QuestionImageModel).contentMode);
Expand Down

0 comments on commit e4e997a

Please sign in to comment.