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

Fixed #5982 - An Image question doesn't display a validation error when replacing an existing image and an image upload error occurs #5993

Merged
merged 1 commit into from
Oct 28, 2024
Merged
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
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
Loading