New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AlarmCallback does not allow clearing of optional fields with default-value #2108

Closed
magicdude4eva opened this Issue Apr 20, 2016 · 2 comments

Comments

Projects
None yet
2 participants
@magicdude4eva

magicdude4eva commented Apr 20, 2016

Problem description

I noticed this on Graylog v1 and Graylog v2 (2.0.0-beta.3). I am not able to delete the value of an optional field which has a default value.

In the example below the field "MYFIELD" will show the default value of "SOME_DEFAULT_VALUE" when editing the plugin properties. If I delete the value in the web-UI, the config-field will take the default-value of the field.

  public ConfigurationRequest getRequestedConfiguration () {
      final ConfigurationRequest configurationRequest = new ConfigurationRequest();

      configurationRequest.addField (new TextField (
          "MYFIELD", "MYFIELDLABEL", "SOME_DEFAULT_VALUE", "DESCRIPTION",
          ConfigurationField.Optional.OPTIONAL));


      return configurationRequest;
  }

How can I provide my AlarmCallback with a default-value during configuration, but then also allow the user to delete that value. The only way to make this work at the moment is to ask the user to enter some string which I then identify in the plugin as an empty value (in this case "null"):

    String myField = getConfigValue (configuration.getString("MYFIELD"));

    private final String getConfigValue(String x) {
        // Dirty work-around to allow empty content on optional fields with default value
        // We return NULL if the field-value is empty or the user has entered "null"
        return (isNullOrEmpty(x) || x.equals("null") ? null : x);
    }

Steps to reproduce the problem

  1. Write a AlarmCallback plugin with an optional field and a default value
  2. Edit the callback-plugin and then try to delete the pre-populated default value
  3. Save
  4. Notice how the default value has overwritten the deleted string

Environment

  • Graylog Version: Graylog 2.0.0-beta.3 (1d03037)

@edmundoa edmundoa self-assigned this Apr 20, 2016

@edmundoa edmundoa added bug web labels Apr 20, 2016

@edmundoa edmundoa added this to the 2.0.0 milestone Apr 20, 2016

@edmundoa

This comment has been minimized.

Member

edmundoa commented Apr 20, 2016

Hi,

Thank you for reporting this!

It looks like there is a bug in the web interface and it's sending the old value to the server. We will fix it for the next release.

edmundoa added a commit that referenced this issue Apr 20, 2016

Allow clearing optional values in plugins
Allow clearing out optional values on pluggable entities. Fixes #2108

@joschi joschi closed this in #2114 Apr 20, 2016

joschi added a commit that referenced this issue Apr 20, 2016

@edmundoa

This comment has been minimized.

Member

edmundoa commented Apr 21, 2016

Changes in #2114 actually create a different problem: default values are not send to the server unless they change. We are working on a fix for it.

@edmundoa edmundoa reopened this Apr 21, 2016

edmundoa added a commit that referenced this issue Apr 21, 2016

Include default values in plugable entities forms
Changes in #2114 caused another issue with the pluggable entities forms:
default values were shown in forms, but never submitted to the server.

These changes move the logic taking care of default values to the
`ConfigurationForm` component, also removing incorrect uses of
`defaultValue` in inputs.

In this way, the object containing the data will contain the default
values at the beginning, and they will be overriden by any input the
user type in them.

Refs #2108

@bernd bernd closed this in #2122 Apr 21, 2016

bernd added a commit that referenced this issue Apr 21, 2016

Include default values in plugable entities forms (#2122)
Changes in #2114 caused another issue with the pluggable entities forms:
default values were shown in forms, but never submitted to the server.

These changes move the logic taking care of default values to the
`ConfigurationForm` component, also removing incorrect uses of
`defaultValue` in inputs.

In this way, the object containing the data will contain the default
values at the beginning, and they will be overriden by any input the
user type in them.

Refs #2108
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment