Have m2o options pull from correct collection

This commit is contained in:
rijkvanzanten
2020-09-24 16:26:08 -04:00
parent ba8be831e8
commit 6ab36e6a85
4 changed files with 40 additions and 20 deletions

View File

@@ -32,7 +32,8 @@ import { defineComponent, toRefs, ref, watch, onMounted, onUnmounted } from '@vu
import FieldListItem from './field-list-item.vue';
import { useFieldsStore } from '@/stores';
import { Field } from '@/types/';
import useFieldTree, { findTree } from '@/composables/use-field-tree';
import useFieldTree from '@/composables/use-field-tree';
import { FieldTree } from './types';
export default defineComponent({
components: { FieldListItem },
@@ -152,10 +153,10 @@ export default defineComponent({
}
function addField(fieldKey: string) {
console.log(fieldKey);
if (!contentEl.value) return;
const field = findTree(tree.value, fieldKey.split('.'));
if (!field) return;
const button = document.createElement('button');
@@ -188,6 +189,16 @@ export default defineComponent({
onInput();
}
function findTree(tree: FieldTree[] | undefined, fieldSections: string[]): FieldTree | undefined {
if (tree === undefined) return undefined;
const fieldObject = tree.find((f) => f.field === fieldSections[0]);
if (fieldObject === undefined) return undefined;
if (fieldSections.length === 1) return fieldObject;
return findTree(fieldObject.children, fieldSections.slice(1));
}
function joinElements(first: HTMLElement, second: HTMLElement) {
first.innerText += second.innerText;
second.remove();