Created by @chemix in Q&As
@chemix
@chemix

Hi, I needed simple toggle implementation from Nette.js so this is my simple service

build configuration

...
     libraries:
       js: [
         'public/js/nittro/NetteBasicFormToggle.js',
       ]
...
       services:
         netteBasicFormToggle: 'App.NetteBasicFormToggle()!'          
...            

NetteBasicFormToggle.js

_context.invoke('App', function (Nette) {

    var NetteBasicFormToggle = _context.extend(function(snippetManager) {
        this._ = {
            snippetManager: snippetManager
        };

        this._.snippetManager.on('after-update', this._handleUpdate.bind(this));
    }, {
        _handleUpdate: function() {
            var forms = [].slice.call(document.getElementsByTagName('form'));
            forms.forEach(Nette.toggleForm);
        }
    });

    _context.register(NetteBasicFormToggle, 'NetteBasicFormToggle');

}, {
    Nette: 'Nittro.Forms.Vendor'
});

thanks @jahudka for help 🙏

Sign in to post a reply