sizzlemctwizzle / GM_config

A lightweight, reusable, cross-browser graphical settings framework for inclusion in user scripts.
https://github.com/sizzlemctwizzle/GM_config/wiki
GNU Lesser General Public License v3.0
205 stars 48 forks source link

radio onChange event #106

Closed Azuzula closed 1 year ago

Azuzula commented 2 years ago

Hi, I'm trying add onChange event for the radio buttons in the GM_config.init. This loop add change event for all radio buttons with name "head"+its number, but I'm geting data from the last one only. Am I doing something wrong or is it bug? I'm dynamically generate sections with radio buttons and text fields. Thank you. `

           'events':{
                'open':  function(doc) {
                    var myRows = GM_config.get('rows');
                    for (var i = 1; i <= myRows; i++){ 
                    var radioName = 'head'+i;
                    GM_config.fields[radioName].node.addEventListener('change', function () {
                        alert(radioName + " " + GM_config.get(radioName, true));
                    }, false);
                    };
                }
            }

`

sizzlemctwizzle commented 1 year ago

The correct way is something like this:

for (var id in GM_config.fields) {
  var field = GM_config.fields[id];
  if (field.type !== 'radio') continue;
  // add listener to node
}