Config UI: trim string values (#20169)
This commit is contained in:
parent
ee157ee447
commit
b649f07287
2 changed files with 12 additions and 2 deletions
|
|
@ -125,7 +125,8 @@ export default {
|
|||
this.saving = true;
|
||||
this.error = "";
|
||||
try {
|
||||
const res = await api[this.saveMethod](this.endpoint, this.values, {
|
||||
const values = this.trimValues(this.values);
|
||||
const res = await api[this.saveMethod](this.endpoint, values, {
|
||||
validateStatus: (code) => [200, 202, 400].includes(code),
|
||||
});
|
||||
if (res.status === 200 || res.status === 202) {
|
||||
|
|
@ -159,6 +160,15 @@ export default {
|
|||
}
|
||||
this.removing = false;
|
||||
},
|
||||
trimValues(values) {
|
||||
// extend to recursive when needed in the future
|
||||
return Object.fromEntries(
|
||||
Object.entries(values).map(([key, value]) => [
|
||||
key,
|
||||
typeof value === "string" ? value.trim() : value,
|
||||
])
|
||||
);
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ test.describe("mqtt", async () => {
|
|||
const modal = await page.getByTestId("mqtt-modal");
|
||||
|
||||
await modal.getByLabel("Broker").fill("unknown.example.org");
|
||||
await modal.getByLabel("Topic").fill("my-topic");
|
||||
await modal.getByLabel("Topic").fill(" my-topic "); // whitespace should be trimmed
|
||||
await modal.getByLabel("Client ID").fill("my-client-id");
|
||||
|
||||
await page.getByRole("button", { name: "Save" }).click();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue