Merge pull request #19971 from dannon/trim-pref-inputs

Adds a trimInputs prop to FormGeneric to trim string values on submit.
This commit is contained in:
Marius van den Beek
2025-04-10 10:08:29 +02:00
committed by GitHub
2 changed files with 17 additions and 2 deletions
+16 -1
View File
@@ -72,6 +72,10 @@ export default {
type: String,
default: null,
},
trimInputs: {
type: Boolean,
default: false,
},
},
data() {
return {
@@ -103,7 +107,18 @@ export default {
window.location = withPrefix(this.cancelRedirect);
},
onSubmit() {
submitData(this.url, this.formData).then((response) => {
const formData = { ...this.formData };
if (this.trimInputs) {
// Trim string values in form data
Object.keys(formData).forEach((key) => {
if (typeof formData[key] === "string") {
formData[key] = formData[key].trim();
}
});
}
submitData(this.url, formData).then((response) => {
let params = {};
if (response.id) {
params.id = response.id;
@@ -1,5 +1,5 @@
<template>
<FormGeneric v-bind="formConfig" />
<FormGeneric v-bind="formConfig" :trim-inputs="true" />
</template>
<script>
import FormGeneric from "components/Form/FormGeneric";