Skip to content

Commit

Permalink
Disallow empty inputs on required input parameters in simplified work…
Browse files Browse the repository at this point in the history
…flow form

This is another attempt at
galaxyproject#13220, but taking into
account
galaxyproject#13220 (comment)
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).
  • Loading branch information
mvdbeek committed Nov 17, 2023
1 parent 26573dd commit da127b5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
6 changes: 5 additions & 1 deletion client/src/components/Form/FormDisplay.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ export default {
type: Boolean,
default: false,
},
allowEmptyValueOnRequiredInput: {
type: Boolean,
default: false,
},
},
data() {
return {
Expand All @@ -89,7 +93,7 @@ export default {
},
computed: {
validation() {
return validateInputs(this.formIndex, this.formData);
return validateInputs(this.formIndex, this.formData, this.allowEmptyValueOnRequiredInput);
},
},
watch: {
Expand Down
8 changes: 5 additions & 3 deletions client/src/components/Form/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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."];
Expand Down
8 changes: 7 additions & 1 deletion client/src/components/Workflow/Run/WorkflowRunFormSimple.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@
</b-dropdown-form>
</b-dropdown>
</div>
<FormDisplay :inputs="formInputs" @onChange="onChange" @onValidation="onValidation" />
<FormDisplay
:inputs="formInputs"
:allowEmptyValueOnRequiredInput="true"
@onChange="onChange"
@onValidation="onValidation" />
<!-- Options to default one way or the other, disable if admins want, etc.. -->
<a href="#" class="workflow-expand-form-link" @click="$emit('showAdvanced')">Expand to full workflow form.</a>
</div>
Expand Down Expand Up @@ -137,6 +141,8 @@ export default {
onValidation(validation) {
if (validation) {
Vue.set(this.stepValidations, validation[0], validation[1]);
} else {
this.stepValidations = {};
}
},
reuseAllowed(user) {
Expand Down

0 comments on commit da127b5

Please sign in to comment.