feat: duplicate field
This commit is contained in:
parent
c9d3449bd3
commit
9cdd4e835d
3 changed files with 25 additions and 6 deletions
|
|
@ -2,7 +2,7 @@
|
|||
import EditableInput from "./EditableInput.vue";
|
||||
import { ref, computed } from "vue";
|
||||
import { useStore } from "../store";
|
||||
import { move_children_to_parent } from "../utils";
|
||||
import { move_children_to_parent, clone_field } from "../utils";
|
||||
|
||||
let props = defineProps(["column", "field"]);
|
||||
let store = useStore();
|
||||
|
|
@ -28,6 +28,20 @@ function move_fields_to_column() {
|
|||
);
|
||||
move_children_to_parent(props, "column", "field", current_section);
|
||||
}
|
||||
|
||||
function duplicate_field() {
|
||||
let duplicate_field = clone_field(props.field);
|
||||
|
||||
if (duplicate_field.df.label) {
|
||||
duplicate_field.df.label = duplicate_field.df.label + " Copy";
|
||||
}
|
||||
duplicate_field.df.fieldname = "";
|
||||
|
||||
// push duplicate_field after props.field in the same column
|
||||
let index = props.column.fields.indexOf(props.field);
|
||||
props.column.fields.splice(index + 1, 0, duplicate_field);
|
||||
store.selected_field = duplicate_field.df;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
|
@ -79,6 +93,9 @@ function move_fields_to_column() {
|
|||
>
|
||||
<div v-html="frappe.utils.icon('move', 'sm')"></div>
|
||||
</button>
|
||||
<button class="btn btn-xs btn-icon" @click.stop="duplicate_field">
|
||||
<div v-html="frappe.utils.icon('duplicate', 'sm')"></div>
|
||||
</button>
|
||||
<button class="btn btn-xs btn-icon" @click.stop="remove_field">
|
||||
<div v-html="frappe.utils.icon('remove', 'sm')"></div>
|
||||
</button>
|
||||
|
|
|
|||
|
|
@ -3,15 +3,11 @@ import SearchBox from "./SearchBox.vue";
|
|||
import draggable from "vuedraggable";
|
||||
import { ref, computed } from "vue";
|
||||
import { useStore } from "../store";
|
||||
import { clone_field } from "../utils";
|
||||
|
||||
let store = useStore();
|
||||
let search_text = ref("");
|
||||
|
||||
function clone_field(field) {
|
||||
field.df.name = frappe.utils.get_random(8);
|
||||
return JSON.parse(JSON.stringify(field));
|
||||
}
|
||||
|
||||
let fields = computed(() => {
|
||||
let fields = frappe.model.all_fieldtypes
|
||||
.filter(df => {
|
||||
|
|
|
|||
|
|
@ -318,3 +318,9 @@ export function scrub_field_names(fields) {
|
|||
|
||||
return fields;
|
||||
}
|
||||
|
||||
export function clone_field(field) {
|
||||
let cloned_field = JSON.parse(JSON.stringify(field));
|
||||
cloned_field.df.name = frappe.utils.get_random(8);
|
||||
return cloned_field;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue