You have access to cocoon
-specific callbacks; in particular, cocoon:after-insert
. You can do something like this (untested):
$(document).ready(function() {
$("#formContainer").on(
"cocoon:after-insert", (event, insertedItem, originalEvent) {
console.log("event: ", event)
console.log("insertedItem: ", insertedItem)
console.log("originalEvent: ", originalEvent)
})
})
Using the original event (the click
event) you can find the fields belonging to that button and get the values from that, and use those values to set the values in the newly inserted item.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…