How to make input type file wait for http request's response before opening file chooser
I have a file chooser in my page.
<input type='file' id='xxx'>
On click of this input, I have to validate some other fields via HTTP request. Now what I want is my file chooser should wait till I get the response from the HTTP request. Is there any way I can achieve this.
On click, I am calling some method which validates everything but before it completes the method execution, file chooser comes up.
I tried for async/sync method call but NO success.
I am using angular 6.
javascript html angular input
|
show 2 more comments
I have a file chooser in my page.
<input type='file' id='xxx'>
On click of this input, I have to validate some other fields via HTTP request. Now what I want is my file chooser should wait till I get the response from the HTTP request. Is there any way I can achieve this.
On click, I am calling some method which validates everything but before it completes the method execution, file chooser comes up.
I tried for async/sync method call but NO success.
I am using angular 6.
javascript html angular input
It is unclear what selecting a file and how the other HTTP requests relate.... Maybe you should show some code.
– epascarello
Nov 13 '18 at 14:28
that is somehow requirement that file chooser should open only after validation which is written over backend.
– Shubham Sharma
Nov 13 '18 at 14:29
1
wouldn't it be wiser to place a stepper of some sort and simply limit access to the file dialog tab ?
– Stavm
Nov 13 '18 at 14:47
1
So do not show it until it can be used.... disable it and show some sort of message "validating....."
– epascarello
Nov 13 '18 at 14:47
1
Sounds like a bad user experience, frankly. When I click on a file input, I expect the file chooser to show up. If it doesn't, I'm going to wonder why the app is so slow. The validation should be triggered by every form element; when enough of them have been filled out that it makes sense to do the HTTP requests, trigger them. As @epascarello suggests, don't allow them to use the file input until the form is valid.
– Heretic Monkey
Nov 13 '18 at 15:01
|
show 2 more comments
I have a file chooser in my page.
<input type='file' id='xxx'>
On click of this input, I have to validate some other fields via HTTP request. Now what I want is my file chooser should wait till I get the response from the HTTP request. Is there any way I can achieve this.
On click, I am calling some method which validates everything but before it completes the method execution, file chooser comes up.
I tried for async/sync method call but NO success.
I am using angular 6.
javascript html angular input
I have a file chooser in my page.
<input type='file' id='xxx'>
On click of this input, I have to validate some other fields via HTTP request. Now what I want is my file chooser should wait till I get the response from the HTTP request. Is there any way I can achieve this.
On click, I am calling some method which validates everything but before it completes the method execution, file chooser comes up.
I tried for async/sync method call but NO success.
I am using angular 6.
javascript html angular input
javascript html angular input
asked Nov 13 '18 at 14:26
Shubham SharmaShubham Sharma
126112
126112
It is unclear what selecting a file and how the other HTTP requests relate.... Maybe you should show some code.
– epascarello
Nov 13 '18 at 14:28
that is somehow requirement that file chooser should open only after validation which is written over backend.
– Shubham Sharma
Nov 13 '18 at 14:29
1
wouldn't it be wiser to place a stepper of some sort and simply limit access to the file dialog tab ?
– Stavm
Nov 13 '18 at 14:47
1
So do not show it until it can be used.... disable it and show some sort of message "validating....."
– epascarello
Nov 13 '18 at 14:47
1
Sounds like a bad user experience, frankly. When I click on a file input, I expect the file chooser to show up. If it doesn't, I'm going to wonder why the app is so slow. The validation should be triggered by every form element; when enough of them have been filled out that it makes sense to do the HTTP requests, trigger them. As @epascarello suggests, don't allow them to use the file input until the form is valid.
– Heretic Monkey
Nov 13 '18 at 15:01
|
show 2 more comments
It is unclear what selecting a file and how the other HTTP requests relate.... Maybe you should show some code.
– epascarello
Nov 13 '18 at 14:28
that is somehow requirement that file chooser should open only after validation which is written over backend.
– Shubham Sharma
Nov 13 '18 at 14:29
1
wouldn't it be wiser to place a stepper of some sort and simply limit access to the file dialog tab ?
– Stavm
Nov 13 '18 at 14:47
1
So do not show it until it can be used.... disable it and show some sort of message "validating....."
– epascarello
Nov 13 '18 at 14:47
1
Sounds like a bad user experience, frankly. When I click on a file input, I expect the file chooser to show up. If it doesn't, I'm going to wonder why the app is so slow. The validation should be triggered by every form element; when enough of them have been filled out that it makes sense to do the HTTP requests, trigger them. As @epascarello suggests, don't allow them to use the file input until the form is valid.
– Heretic Monkey
Nov 13 '18 at 15:01
It is unclear what selecting a file and how the other HTTP requests relate.... Maybe you should show some code.
– epascarello
Nov 13 '18 at 14:28
It is unclear what selecting a file and how the other HTTP requests relate.... Maybe you should show some code.
– epascarello
Nov 13 '18 at 14:28
that is somehow requirement that file chooser should open only after validation which is written over backend.
– Shubham Sharma
Nov 13 '18 at 14:29
that is somehow requirement that file chooser should open only after validation which is written over backend.
– Shubham Sharma
Nov 13 '18 at 14:29
1
1
wouldn't it be wiser to place a stepper of some sort and simply limit access to the file dialog tab ?
– Stavm
Nov 13 '18 at 14:47
wouldn't it be wiser to place a stepper of some sort and simply limit access to the file dialog tab ?
– Stavm
Nov 13 '18 at 14:47
1
1
So do not show it until it can be used.... disable it and show some sort of message "validating....."
– epascarello
Nov 13 '18 at 14:47
So do not show it until it can be used.... disable it and show some sort of message "validating....."
– epascarello
Nov 13 '18 at 14:47
1
1
Sounds like a bad user experience, frankly. When I click on a file input, I expect the file chooser to show up. If it doesn't, I'm going to wonder why the app is so slow. The validation should be triggered by every form element; when enough of them have been filled out that it makes sense to do the HTTP requests, trigger them. As @epascarello suggests, don't allow them to use the file input until the form is valid.
– Heretic Monkey
Nov 13 '18 at 15:01
Sounds like a bad user experience, frankly. When I click on a file input, I expect the file chooser to show up. If it doesn't, I'm going to wonder why the app is so slow. The validation should be triggered by every form element; when enough of them have been filled out that it makes sense to do the HTTP requests, trigger them. As @epascarello suggests, don't allow them to use the file input until the form is valid.
– Heretic Monkey
Nov 13 '18 at 15:01
|
show 2 more comments
1 Answer
1
active
oldest
votes
I think you need somethink like this.
UPDT: sorry, fixed example to work
@Directive({
selector: '[validateClick]'
})
export class ValidateClickDirective {
private _isValid: boolean = false;
constructor(
private _elementRef: ElementRef<HTMLElement>
) { }
@HostListener('click', ['$event'])
public onClick(event: MouseEvent): void {
if (!this._isValid) {
event.preventDefault();
of(true) // your request to the server
.pipe(delay(1000))
.subscribe((isValid: boolean) => {
this._isValid = isValid
if (isValid) {
this._elementRef.nativeElement.click();
}
})
} else {
this._isValid = false;
}
}
}
And use it:
<input type="file" validateClick>
Implemented in the same way but can see file chooser. :(
– Shubham Sharma
Nov 13 '18 at 16:07
@ShubhamSharma make sure u write<input type="file" validateClick>
without #
– Swagga
Nov 13 '18 at 18:59
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53283198%2fhow-to-make-input-type-file-wait-for-http-requests-response-before-opening-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I think you need somethink like this.
UPDT: sorry, fixed example to work
@Directive({
selector: '[validateClick]'
})
export class ValidateClickDirective {
private _isValid: boolean = false;
constructor(
private _elementRef: ElementRef<HTMLElement>
) { }
@HostListener('click', ['$event'])
public onClick(event: MouseEvent): void {
if (!this._isValid) {
event.preventDefault();
of(true) // your request to the server
.pipe(delay(1000))
.subscribe((isValid: boolean) => {
this._isValid = isValid
if (isValid) {
this._elementRef.nativeElement.click();
}
})
} else {
this._isValid = false;
}
}
}
And use it:
<input type="file" validateClick>
Implemented in the same way but can see file chooser. :(
– Shubham Sharma
Nov 13 '18 at 16:07
@ShubhamSharma make sure u write<input type="file" validateClick>
without #
– Swagga
Nov 13 '18 at 18:59
add a comment |
I think you need somethink like this.
UPDT: sorry, fixed example to work
@Directive({
selector: '[validateClick]'
})
export class ValidateClickDirective {
private _isValid: boolean = false;
constructor(
private _elementRef: ElementRef<HTMLElement>
) { }
@HostListener('click', ['$event'])
public onClick(event: MouseEvent): void {
if (!this._isValid) {
event.preventDefault();
of(true) // your request to the server
.pipe(delay(1000))
.subscribe((isValid: boolean) => {
this._isValid = isValid
if (isValid) {
this._elementRef.nativeElement.click();
}
})
} else {
this._isValid = false;
}
}
}
And use it:
<input type="file" validateClick>
Implemented in the same way but can see file chooser. :(
– Shubham Sharma
Nov 13 '18 at 16:07
@ShubhamSharma make sure u write<input type="file" validateClick>
without #
– Swagga
Nov 13 '18 at 18:59
add a comment |
I think you need somethink like this.
UPDT: sorry, fixed example to work
@Directive({
selector: '[validateClick]'
})
export class ValidateClickDirective {
private _isValid: boolean = false;
constructor(
private _elementRef: ElementRef<HTMLElement>
) { }
@HostListener('click', ['$event'])
public onClick(event: MouseEvent): void {
if (!this._isValid) {
event.preventDefault();
of(true) // your request to the server
.pipe(delay(1000))
.subscribe((isValid: boolean) => {
this._isValid = isValid
if (isValid) {
this._elementRef.nativeElement.click();
}
})
} else {
this._isValid = false;
}
}
}
And use it:
<input type="file" validateClick>
I think you need somethink like this.
UPDT: sorry, fixed example to work
@Directive({
selector: '[validateClick]'
})
export class ValidateClickDirective {
private _isValid: boolean = false;
constructor(
private _elementRef: ElementRef<HTMLElement>
) { }
@HostListener('click', ['$event'])
public onClick(event: MouseEvent): void {
if (!this._isValid) {
event.preventDefault();
of(true) // your request to the server
.pipe(delay(1000))
.subscribe((isValid: boolean) => {
this._isValid = isValid
if (isValid) {
this._elementRef.nativeElement.click();
}
})
} else {
this._isValid = false;
}
}
}
And use it:
<input type="file" validateClick>
edited Nov 13 '18 at 18:58
answered Nov 13 '18 at 14:44
SwaggaSwagga
6113
6113
Implemented in the same way but can see file chooser. :(
– Shubham Sharma
Nov 13 '18 at 16:07
@ShubhamSharma make sure u write<input type="file" validateClick>
without #
– Swagga
Nov 13 '18 at 18:59
add a comment |
Implemented in the same way but can see file chooser. :(
– Shubham Sharma
Nov 13 '18 at 16:07
@ShubhamSharma make sure u write<input type="file" validateClick>
without #
– Swagga
Nov 13 '18 at 18:59
Implemented in the same way but can see file chooser. :(
– Shubham Sharma
Nov 13 '18 at 16:07
Implemented in the same way but can see file chooser. :(
– Shubham Sharma
Nov 13 '18 at 16:07
@ShubhamSharma make sure u write
<input type="file" validateClick>
without #– Swagga
Nov 13 '18 at 18:59
@ShubhamSharma make sure u write
<input type="file" validateClick>
without #– Swagga
Nov 13 '18 at 18:59
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53283198%2fhow-to-make-input-type-file-wait-for-http-requests-response-before-opening-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
It is unclear what selecting a file and how the other HTTP requests relate.... Maybe you should show some code.
– epascarello
Nov 13 '18 at 14:28
that is somehow requirement that file chooser should open only after validation which is written over backend.
– Shubham Sharma
Nov 13 '18 at 14:29
1
wouldn't it be wiser to place a stepper of some sort and simply limit access to the file dialog tab ?
– Stavm
Nov 13 '18 at 14:47
1
So do not show it until it can be used.... disable it and show some sort of message "validating....."
– epascarello
Nov 13 '18 at 14:47
1
Sounds like a bad user experience, frankly. When I click on a file input, I expect the file chooser to show up. If it doesn't, I'm going to wonder why the app is so slow. The validation should be triggered by every form element; when enough of them have been filled out that it makes sense to do the HTTP requests, trigger them. As @epascarello suggests, don't allow them to use the file input until the form is valid.
– Heretic Monkey
Nov 13 '18 at 15:01