Skip to content

Commit

Permalink
Fixed #7820 - [React, Angular] File Uplod - A file chooser dialog is …
Browse files Browse the repository at this point in the history
…invoked twice
  • Loading branch information
tsv2013 committed Feb 8, 2024
1 parent c081dc0 commit d85e4a8
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<ng-template #template>
<label tabindex="0" [class]="question.getChooseFileCss()"
[attr.for]="question.inputId" [attr.aria-label]="question.chooseButtonText" [key2click]
(click)="question.chooseFile()">
(click)="question.chooseFile($event)">
<svg *ngIf="question.cssClasses.chooseFileIconId" [title]="question.chooseButtonText"
[iconName]="question.cssClasses.chooseFileIconId" [size]="'auto'" sv-ng-svg-icon></svg>
<span>{{ question.chooseButtonText }}</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
:for="question.inputId"
v-bind:aria-label="question.chooseButtonText"
v-key2click
v-on:click="question.chooseFile()"
v-on:click="question.chooseFile($event)"
>
<sv-svg-icon
v-if="question.cssClasses.chooseFileIconId"
Expand Down
2 changes: 1 addition & 1 deletion src/knockout/components/file/choose-file.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<label tabindex="0" data-bind="css: question.koChooseFileCss, key2click, click: function() { question.chooseFile(); }, attr: { for: question.inputId, 'aria-label': question.koGetChooseButtonText() }">
<label tabindex="0" data-bind="css: question.koChooseFileCss, key2click, click: function(d, e) { question.chooseFile(e); }, attr: { for: question.inputId, 'aria-label': question.koGetChooseButtonText() }">
<!-- ko if: question.cssClasses.chooseFileIconId -->
<!-- ko component: { name: 'sv-svg-icon', params: { title: question.koGetChooseButtonText(), iconName: question.cssClasses.chooseFileIconId, size: 'auto' } } --><!-- /ko -->
<!-- /ko -->
Expand Down
4 changes: 3 additions & 1 deletion src/question_file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,10 @@ export class QuestionFileModel extends QuestionFileModelBase {
public set maxSize(val: number) {
this.setPropertyValue("maxSize", val);
}
public chooseFile(): void {
public chooseFile(event: MouseEvent): void {
const inputElement = document.getElementById(this.inputId) as HTMLInputElement;
event.preventDefault();
event.stopImmediatePropagation();
if (inputElement) {
if (this.survey) {
this.survey.chooseFiles(inputElement, files => this.loadFiles(files), { element: this });
Expand Down
2 changes: 1 addition & 1 deletion src/react/components/file/file-choose-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class SurveyFileChooseButton extends ReactSurveyElement {
className={this.question.getChooseFileCss()}
htmlFor={this.question.inputId}
aria-label={this.question.chooseButtonText}
onClick={() => this.question.chooseFile()}
onClick={(e) => this.question.chooseFile(e.nativeEvent)}
>
{(!!this.question.cssClasses.chooseFileIconId) ? <SvgIcon title={this.question.chooseButtonText} iconName={this.question.cssClasses.chooseFileIconId} size={"auto"}></SvgIcon>: null }
<span>{this.question.chooseButtonText}</span>
Expand Down
2 changes: 1 addition & 1 deletion src/vue/components/file/file-choose-button.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
:for="question.inputId"
v-bind:aria-label="question.chooseButtonText"
v-key2click
v-on:click="function() { question.chooseFile(); }"
v-on:click="function(event) { question.chooseFile(event); }"
>
<sv-svg-icon
v-if="question.cssClasses.chooseFileIconId"
Expand Down

0 comments on commit d85e4a8

Please sign in to comment.