Skip to content
Snippets Groups Projects
Commit c55ca323 authored by Julian's avatar Julian
Browse files

Add element validation function

parent e753b1a5
No related branches found
No related tags found
1 merge request!2Resolve "Implement basic functionality"
...@@ -20,6 +20,7 @@ import CircularCard from "./components/CircularCard.vue"; ...@@ -20,6 +20,7 @@ import CircularCard from "./components/CircularCard.vue";
v-model="ticTacToe1" v-model="ticTacToe1"
class="tic-tac-toe" class="tic-tac-toe"
context="ticTacToe" context="ticTacToe"
:validate-element="randomKey"
> >
<template #item="item"> <template #item="item">
<CircularCard> <CircularCard>
...@@ -27,13 +28,17 @@ import CircularCard from "./components/CircularCard.vue"; ...@@ -27,13 +28,17 @@ import CircularCard from "./components/CircularCard.vue";
> >
</template> </template>
</DragGrid> </DragGrid>
<span> These two are two different grids but are interchangeable! </span> <div>
<p>These two are two different grids but we can drag from right to left!</p>
<p>Drag items from the container on the right to play on the left.</p>
</div>
<DragGrid <DragGrid
:rows="3" :rows="1"
:cols="3" :cols="2"
v-model="ticTacToe2" v-model="ticTacToe2"
class="tic-tac-toe" class="tic-tac-toe"
context="ticTacToe" context="ticTacToe"
:pos-validation="blockAllMoving"
> >
<template #item="item"> <template #item="item">
<CircularCard> <CircularCard>
...@@ -54,6 +59,13 @@ export default { ...@@ -54,6 +59,13 @@ export default {
if (x === 4 && y === 3) return false; if (x === 4 && y === 3) return false;
return key !== "obj8"; return key !== "obj8";
}, },
blockAllMoving() {
return false;
},
randomKey(element) {
if (element.key !== "a" && element !== "b") return;
element.key += Math.random().toString(36).replace('0.', '');
},
}, },
data() { data() {
return { return {
...@@ -77,14 +89,12 @@ export default { ...@@ -77,14 +89,12 @@ export default {
], ],
ticTacToe1: [ ticTacToe1: [
{ x: 1, y: 1, w: 1, h: 1, key: "a1", data: {} }, { x: 1, y: 1, w: 1, h: 1, key: "a1", data: {} },
{ x: 1, y: 3, w: 1, h: 1, key: "a2", data: {} },
{ x: 2, y: 2, w: 1, h: 1, key: "a3", data: {} },
{ x: 3, y: 2, w: 1, h: 1, key: "a4", data: {} },
{ x: 3, y: 3, w: 1, h: 1, key: "b1", data: {} }, { x: 3, y: 3, w: 1, h: 1, key: "b1", data: {} },
{ x: 1, y: 2, w: 1, h: 1, key: "b2", data: {} },
{ x: 3, y: 1, w: 1, h: 1, key: "b3", data: {} },
], ],
ticTacToe2: [{ x: 1, y: 1, w: 1, h: 1, key: "b4", data: {} }], ticTacToe2: [
{ x: 1, y: 1, w: 1, h: 1, key: "a", data: {} },
{ x: 2, y: 1, w: 1, h: 1, key: "b", data: {} },
],
}; };
}, },
}; };
......
...@@ -58,6 +58,10 @@ export default { ...@@ -58,6 +58,10 @@ export default {
type: Function, type: Function,
required: false, required: false,
}, },
validateElement: {
type: Function,
required: false,
},
value: { value: {
type: Array, type: Array,
required: true, required: true,
...@@ -120,7 +124,8 @@ export default { ...@@ -120,7 +124,8 @@ export default {
this.$refs.highlight.style.display = "none"; this.$refs.highlight.style.display = "none";
let data = event.dataTransfer.getData("vueDrag/gridItem"); let data = event.dataTransfer.getData("vueDrag/gridItem");
let element = JSON.parse(data); let element = JSON.parse(data);
console.log(element, this.context);
if (this.validateElement) this.validateElement(element);
if (element.context !== this.context) { if (element.context !== this.context) {
return; return;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment