fix: link field shown only for Link fieldtype

This commit is contained in:
RitvikSardana 2023-11-23 13:12:16 +05:30
parent 31e3b3f981
commit 89dbb42f6f
3 changed files with 18 additions and 5 deletions

View file

@ -174,8 +174,13 @@ function edit_filters() {
}
function is_filter_applied() {
if (props.field.df.link_filters && JSON.parse(props.field.df.link_filters).length > 0) {
return "btn-filter-applied";
if (props.field.df.link_filters) {
try {
JSON.parse(props.field.df.link_filters).length > 0;
return "btn-filter-applied";
} catch (error) {
return "";
}
}
}

View file

@ -51,6 +51,11 @@ let docfield_df = computed(() => {
}
}
// show link_filters docfield only when link field is selected
if (df.fieldname === "link_filters" && store.form.selected_field.fieldtype !== "Link") {
return false;
}
if (search_text.value) {
if (
df.label.toLowerCase().includes(search_text.value.toLowerCase()) ||
@ -62,7 +67,6 @@ let docfield_df = computed(() => {
}
return true;
});
return [...fields];
});
</script>

View file

@ -202,14 +202,18 @@ export const useStore = defineStore("form-builder-store", () => {
);
}
// check if link_filters format is correct or not
if (df.link_filters === "") {
delete df.link_filters;
}
// check if link_filters format is correct or not
if (df.link_filters) {
try {
let link_filters = JSON.parse(df.link_filters);
} catch (e) {
error_message = __(
`Invalid Filter Format. Try using filter icon on the field to set it correctly`
"Invalid Filter Format for field {0} of type {1}. Try using filter icon on the field to set it correctly",
get_field_data(df)
);
}
}