How would you create a custom field in a content type that can add a new field in on demand? I’ve successfully was able to add text fields, but I’d like to add the block editor field as well.
Here’s what I have so far
<div id="dynamicFieldsContainer"></div>
<button id="addFieldButton">Add New Field</button>
<script>
let fieldCount = 0; // Initialize a counter for the fields
document.getElementById('addFieldButton').addEventListener('click', function() {
fieldCount++; // Increment counter with each button press
// Create a new paragraph element for the heading input
const paragraph = document.createElement('p');
// Create a new text field for heading
const textField = document.createElement('input');
textField.type = 'text';
textField.placeholder = `Heading ${fieldCount}`; // Dynamic placeholder
textField.name = `heading${fieldCount}`; // Unique name for the text field
// Append the text field to the paragraph
paragraph.appendChild(textField);
// HOW DO I ADD THE BLOCK EDITOR HERE?
});
</script>