Lets say I have the following html..
<select name="certificatesSelect"
ng-model="$ctrl.selectedCertificate"
ng-change="$ctrl.onSelectCertificate()"
ng-options="certificate as certificate.name for certificate in $ctrl.certificateDropdownOptions track by certificate.id">
<input id="certificate-upload-file-input"
type="file"
style="visibility: hidden"
accept=".der,.crt"/>
One of my options that are populated by ng-options is a "Browse..." option. When the user selects the 'Browse...' option from the select box, I want to be able to pull up the file upload window provided by the browser, i.e the same action as if the user clicked on the file type input box.
My initial attempt at this was something as follows where on my controller I had the onSelectCertificate function bound to change event of the select box.
onSelectCertificate() {
// if the selected option is the "Browse..." option
if (this.selectedCertificate.id === this.BROWSE_OPTION_ID) {
// find the input element and click on it
this.certificateFileInput = this.$element.find("input[type='file']");
this.$timeout(() => {
this.certificateFileInput.click();
}, 0);
}
}
However, this does not work. After some reading online, I believe this is because of a security concern where only a USER issued click event can trigger another click event through javascript. Therefore, the ng-change binding for the select box can not trigger my own click event through javascript. Now, my question is, are there any other ways to achieve this select box design?