Home › Forums › Gutenberg › Limit amount of Innerblocks to x number › Reply To: Limit amount of Innerblocks to x number
@heerko @duck life
First, you need to create a counter variable that keeps track of the number of blocks that have been added. You can do this by creating a variable count that is initialized to 0.
Next, you will need to create a function that increments the count variable each time a new block is added. You can do this by creating a function addBlock that increments the count variable by 1 each time it is called.
Then, you will need to bind the addBlock function to the appender so that it is called each time a new block is added.
Finally, you can use an if statement to check the value of count and hide the appender if count is equal to 2.
Here is some example code that demonstrates how you could implement this:
let count = 0;
function addBlock() {
count += 1;
if (count === 2) {
// hide the appender here
}
}
// bind the addBlock function to the appender
document.getElementById("appender").addEventListener("click", addBlock);
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.