sizzlemctwizzle/GM_config

Field value change event

Opened this issue · 0 comments

Would be nice if there was a way to subscribe to all kind of field value changes, Currently, if I;m not mistaken, you have to do:

config.onOpen = function() {
  let reverseGeocodingAPIField = this.fields.reverseGeocodingAPI.node;
  let changeReverseGeocodingAPIVisibility = value => {
    if (value === 'BigDataCloud') {
      this.fields.bigDataCloudAPIKey.wrapper.style.display = '';
    } else {
      this.fields.bigDataCloudAPIKey.wrapper.style.display = 'none';
    }
  };

  changeReverseGeocodingAPIVisibility(reverseGeocodingAPIField.value);

  reverseGeocodingAPIField.addEventListener(
    'change',
    event => changeReverseGeocodingAPIVisibility(event.target.value)
  );
}

to check both initial state and then changes. Not too clean if yyou did that for a bunch of fields.

It could be e.g.: config.fieldName.onValueChange/config.fields.fieldName.onValueChange or something similar.