I need to populate a matrix block field with JavaScript in the control panel. I've got the data ready, but i can't figure out how to add it.
I've located a function called addBlock()
in MatrixInput.js
but I can not figure out how to call it from my JS code. I've explored both the global Craft
and Garnish
- without finding the function. I could recreate the entire html of the element, but that seems unnecessary when there are helper functions that I could reach for.
Looks like craft is creating one var for each block available on the page with the following code:
var matrixInput = new Craft.MatrixInput("...")
var matrixInput = new Craft.MatrixInput("...")
It would also be great to have the arguments that needs to be passed to the function - is there any documentation or anyone who struggled with this previously that can point me in the right direction?