.getElementById(`${this.formFieldId}_instructions${instructionsId}_pip`)!
.addEventListener("change", (ev) => this.changeInstructionPip(ev));
- document
- .getElementById(`${this.formFieldId}_instructions${instructionsId}_value`)!
- .addEventListener("keypress", (ev) => this.instructionKeyPress(ev));
+ const value = document.getElementById(
+ `${this.formFieldId}_instructions${instructionsId}_value`,
+ ) as HTMLInputElement;
+ value.addEventListener("keypress", (ev) => this.instructionKeyPress(ev));
+
+ const application = document.getElementById(
+ `${this.formFieldId}_instructions${instructionsId}_application`,
+ ) as HTMLSelectElement;
+ application.addEventListener("focus", () => this.#deriveApplicationFromPipName(application, value));
document
.getElementById(`${this.formFieldId}_instructions${instructionsId}_addButton`)!
}
}
+ #deriveApplicationFromPipName(application: HTMLSelectElement, value: HTMLInputElement): void {
+ if (application.value !== "") {
+ return;
+ }
+
+ const matches = value.value.trim().match(/_([a-z]+).tar$/);
+ if (matches !== null) {
+ const isValid = Array.from(application.options).some((option) => option.value === matches[1]);
+ if (isValid) {
+ application.value = matches[1];
+ }
+ }
+ }
+
/**
* Is called if the selected package installation plugin of an instruction is changed.
*/
document
.getElementById(`${this.formFieldId}_instructions${instructionsId}_pip`)
.addEventListener("change", (ev) => this.changeInstructionPip(ev));
- document
- .getElementById(`${this.formFieldId}_instructions${instructionsId}_value`)
- .addEventListener("keypress", (ev) => this.instructionKeyPress(ev));
+ const value = document.getElementById(`${this.formFieldId}_instructions${instructionsId}_value`);
+ value.addEventListener("keypress", (ev) => this.instructionKeyPress(ev));
+ const application = document.getElementById(`${this.formFieldId}_instructions${instructionsId}_application`);
+ application.addEventListener("focus", () => this.#deriveApplicationFromPipName(application, value));
document
.getElementById(`${this.formFieldId}_instructions${instructionsId}_addButton`)
.addEventListener("click", (ev) => this.addInstruction(ev));
});
}
}
+ #deriveApplicationFromPipName(application, value) {
+ if (application.value !== "") {
+ return;
+ }
+ const matches = value.value.trim().match(/_([a-z]+).tar$/);
+ if (matches !== null) {
+ const isValid = Array.from(application.options).some((option) => option.value === matches[1]);
+ if (isValid) {
+ application.value = matches[1];
+ }
+ }
+ }
/**
* Is called if the selected package installation plugin of an instruction is changed.
*/