Search code examples
meteormeteor-autoform

Stop users from removing subdocuments in Autoform


What should happen is a user can add a subdocument with the big [+] button, but cannot remove it without a prompt. Basically just deleting the [-] button. How do I do that? Can I do that?

If it can't be done I have other solutions to my problem, but that seems to defeat the purpose of the using this package.


Solution

  • Yes, you can remove the [-] button.

    For add new document you have to write a following code in the events.

    Template.TemplateName.events({  
        "click .autoform-add-item" :function(){
           //This allow to remove the current [-] button as well.
            setTimeout(function(){
                $('.autoform-remove-item').remove();
            });
        },
    });
    

    For add edit document you have to add the remove [-] button code in onRendered block as well, like :

    Template.TemplateName.onRendered(function () {
        $('.autoform-remove-item').remove();
    });
    

    @Note :: Please make sure then you have "autoform-add-item" class on [+] button and "autoform-remove-item" on [-] button. You can check these classes using inspect element.