Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Jammyman's avatar

Storing drag & drop content and order

I'm building a drag & drop form editor. I was thinking that all different form fields, like checkbox, textfield etc. could be different components. Then I can keep track of the different components in the array and show them like in example below.

It's easy to add and change the order of the components dynamically. But I'm having hard time figuring out how to how loop thru the Items array and access the component inside it when I would like to store it to database. How do I get component inside the list item (build the connection)? Or is there better way to do this?

Items array:

data: {
    items: [
        {type: 'checkbox-component'},
        {type: 'textfield-component'},
        {type: 'textfield-component'},
    ]
}

View:

<ul>
    <li v-for="item in items">
        <template v-if="item.type == 'checkbox-component'">
                        <checkbox-component></checkbox-component>
        </template>
        <template v-if="item.type == 'textfield-component'">
                        <textfield-component></textfield-component>
        </template>
    </li>
</ul>
0 likes
2 replies
Jammyman's avatar

Thanks for the tip about the Dragula!

Yeah, I'm probably going to wrap them to another component, maybe called "block". Because it can contain other stuff too.

Looks like the answer what I was looking for was simple as "this.$children".

It returns all components below another and I can get the order and the data :)

Please or to participate in this conversation.