Uploaded image for project: 'SR for Jira - Development'
  1. SR for Jira - Development
  2. SRJIRA-4112

Behaviours - Change Event not fired for checkbox and Radio button fields that have had their options changed by a behaviour so field level scripts will not run

    Details

    • Type: Bug
    • Status: Done (View Workflow)
    • Priority: High
    • Resolution: Done
    • Affects Version/s: None
    • Fix Version/s: 6.2.0
    • Component/s: Behaviours
    • Labels:
    • Sprint:
      SR4J Sprint 78, SR4J Sprint 79
    • Critical Points:
      4.9

      Description

      It appears that if you change the options on a CheckBox or a Radio button field using behaviours and then try to alter the properties of that field using, for example, the formfield.setError() method in a field level behaviour script it will silently fail and not do anything because no change events are fired.

      Steps to reproduce.

      1. Make an initialiser that changes the options on a checkbox field like the example here.
      2. Attach another behaviour to the checkbox field that sets an error on the checkbox field for any interaction by the user.

      Video example here CheckBoxSetErrorCustomOptionsBug.mp4

       

      Update:

      The underlying cause of this is that the field change events are no longer fired after you change a checkbox or radio button fields Options from a behaviour script.

      You can test this by setting the options of the checkbox field to have 3 options [Yes, No, Maybe]

      Use this script to set the options in a behaviour initialiser:

      import com.atlassian.jira.component.ComponentAccessor
      import com.atlassian.jira.issue.CustomFieldManager
      import com.atlassian.jira.issue.customfields.manager.OptionsManager
      import com.atlassian.jira.issue.customfields.option.Option
      import com.onresolve.jira.groovy.user.FieldBehaviours
      import org.apache.log4j.Logger
      import org.apache.log4j.Level
      import groovy.transform.BaseScript
      
      @BaseScript FieldBehaviours fieldBehaviours
      def log = Logger.getLogger(getClass())
      log.setLevel(Level.DEBUG)
      
      
      getFieldByName("CheckBoxA").setFieldOptions(getOptionsForField("CheckBoxA").findAll {
          it.value in ["Yes", "Maybe"]
      })
      
      List<Option> getOptionsForField(String cfName) {
          CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
          OptionsManager optionsManager = ComponentAccessor.getOptionsManager()
          def field = getFieldByName(cfName)
          def customField = customFieldManager.getCustomFieldObject(field.getFieldId())
          def config = customField.getRelevantConfig(getIssueContext())
          optionsManager.getOptions(config)
      } 
      

      And add this as the checkbox fields server-side script:

      import com.onresolve.jira.groovy.user.FieldBehaviours
      import org.apache.log4j.Logger
      import org.apache.log4j.Level
      import groovy.transform.BaseScript
      
      @BaseScript FieldBehaviours fieldBehaviours
      def log = Logger.getLogger(getClass())
      log.setLevel(Level.DEBUG)
      
      log.debug("-------------BEHAVIOUR RUNNING----------------")
      

      The log output will not fire after the checkbox options have been altered. If you remove the initialiser, the log output will then show when the user interacts with the checkbox field.

       

        Attachments

          Structure

            Activity

              People

              Assignee:
              jechlin Jamie Echlin
              Reporter:
              mclark Matthew Clark
              Votes:
              1 Vote for this issue
              Watchers:
              6 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Structure Helper Panel