Skip to content

Commit 504a999

Browse files
committed
crm: update tags on edit
1 parent 8eda4cf commit 504a999

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/packages/frontend/frame-editors/crm-editor/fields/string-tags.tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,20 @@ render({ type: "string-tags", editable: true }, ({ field, obj, spec }) => {
2525
const ref = useRef<any>(undefined);
2626
const { save, saving, counter, edit, error, ClickToEdit } =
2727
useEditableContext<string>(field);
28-
const [value, setValue] = useState<string>(obj[field]?.join(",") ?? "");
28+
const [value, setValue] = useState<string>(obj[field]?.join(", ") ?? "");
2929
useEffect(() => {
30-
setValue(obj[field]);
30+
setValue(obj[field]?.join(", ") ?? "");
3131
}, [counter, obj[field]]);
3232

3333
if (spec.type != "string-tags" || !spec.editable) {
3434
throw Error("bug");
3535
}
3636
if (!edit) {
37-
const tags = obj[field];
3837
return (
39-
<ClickToEdit empty={!tags || tags.length == 0}>
38+
<ClickToEdit empty={!value.trim()}>
4039
<div style={{ lineHeight: "2em", display: "inline-block" }}>
41-
{tags?.map((value) => (
42-
<Tag key={value}>{value}</Tag>
40+
{value.split(",").map((tag) => (
41+
<Tag key={value}>{tag.trim()}</Tag>
4342
))}
4443
</div>
4544
</ClickToEdit>
@@ -58,11 +57,17 @@ render({ type: "string-tags", editable: true }, ({ field, obj, spec }) => {
5857
}}
5958
onBlur={() => {
6059
setValue(ref.current.input.value);
61-
save(obj, ref.current.input.value.split(","));
60+
save(
61+
obj,
62+
ref.current.input.value.split(",").map((x) => x.trim()),
63+
);
6264
}}
6365
onPressEnter={() => {
6466
setValue(ref.current.input.value);
65-
save(obj, ref.current.input.value.split(","));
67+
save(
68+
obj,
69+
ref.current.input.value.split(",").map((x) => x.trim()),
70+
);
6671
}}
6772
/>
6873
{error}

0 commit comments

Comments
 (0)