From da127b5b834b5ce26fb9c056a836e4cff13a7c3d Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Fri, 17 Nov 2023 18:32:38 +0100 Subject: [PATCH] Disallow empty inputs on required input parameters in simplified workflow form This is another attempt at https://github.com/galaxyproject/galaxy/issues/13220, but taking into account https://github.com/galaxyproject/galaxy/issues/13220#issuecomment-1068054414 by limiting this to the simplified workflow form, where we can assume input parameter optionality to have the correct meaning. This makes it harder to submit a mandatory text parameter that can be empty, but that is (at this point at least) a very fringe requirement. If really needed you can make the parameter optional (and use pick_value to fill in an empty string if null is not OK as a value). --- client/src/components/Form/FormDisplay.vue | 6 +++++- client/src/components/Form/utilities.js | 8 +++++--- .../src/components/Workflow/Run/WorkflowRunFormSimple.vue | 8 +++++++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/client/src/components/Form/FormDisplay.vue b/client/src/components/Form/FormDisplay.vue index 9d7f86e684d8..db41b879e76e 100644 --- a/client/src/components/Form/FormDisplay.vue +++ b/client/src/components/Form/FormDisplay.vue @@ -79,6 +79,10 @@ export default { type: Boolean, default: false, }, + allowEmptyValueOnRequiredInput: { + type: Boolean, + default: false, + }, }, data() { return { @@ -89,7 +93,7 @@ export default { }, computed: { validation() { - return validateInputs(this.formIndex, this.formData); + return validateInputs(this.formIndex, this.formData, this.allowEmptyValueOnRequiredInput); }, }, watch: { diff --git a/client/src/components/Form/utilities.js b/client/src/components/Form/utilities.js index aff9fa2ba0ba..58b18d79d914 100644 --- a/client/src/components/Form/utilities.js +++ b/client/src/components/Form/utilities.js @@ -104,7 +104,7 @@ export function matchInputs(index, response) { * @param{dict} index - Index of input elements * @param{dict} values - Dictionary of parameter values */ -export function validateInputs(index, values) { +export function validateInputs(index, values, allowEmptyValueOnRequiredInput = false) { let batchN = -1; let batchSrc = null; for (const inputId in values) { @@ -113,8 +113,10 @@ export function validateInputs(index, values) { if (!inputDef || inputDef.step_linked) { continue; } - if (inputValue == null && !inputDef.optional && inputDef.type != "hidden") { - return [inputId, "Please provide a value for this option."]; + if (!inputDef.optional && inputDef.type != "hidden") { + if (inputValue == null || (allowEmptyValueOnRequiredInput && inputValue === "")) { + return [inputId, "Please provide a value for this option."]; + } } if (inputDef.wp_linked && inputDef.text_value == inputValue) { return [inputId, "Please provide a value for this workflow parameter."]; diff --git a/client/src/components/Workflow/Run/WorkflowRunFormSimple.vue b/client/src/components/Workflow/Run/WorkflowRunFormSimple.vue index c73b8b58ff7e..b0a166144c49 100644 --- a/client/src/components/Workflow/Run/WorkflowRunFormSimple.vue +++ b/client/src/components/Workflow/Run/WorkflowRunFormSimple.vue @@ -43,7 +43,11 @@ - + Expand to full workflow form. @@ -137,6 +141,8 @@ export default { onValidation(validation) { if (validation) { Vue.set(this.stepValidations, validation[0], validation[1]); + } else { + this.stepValidations = {}; } }, reuseAllowed(user) {