Manipulating Dialogue Fields in AEM 6.1



I have a requirement where I have multiple sets in a dialogue, I want the user to fill only the top 3 sets and not beyond that. I cannot remove the multiple sets. I need to display an error message on the author page once the user clicks 'ok' on the dialogue after filling the fourth set. I can probably have the error message in a text component on the page to be displayed on the condition. How do I execute the display of that text component based on the number of field sets that the user is filling in the dialogue.

Any leads would be helpful.