Set a Macro-Editor-Field "editable false" or "read only"

Hi,

I have a macro with the String-Parameter “prefix”.

“prefix” shall be set on creating the macro (empty string is allowed).
After that, it must not be editable.

<atlassian-plugin key="${atlassian.plugin.key}" name="${project.name}" plugins-version="2">
   <!-- ... -->

   <web-resource key="MyPlugin-resources" name="Web Resources">
      <!-- ... -->
      <resource type="download" name="my.js" location="/js/my.js"/>
      <dependency>confluence.editor.actions:editor-macro-browser</dependency>
      <context>macro-browser</context>
    </web-resource>

  <xhtml-macro name="mymacro" class="com.company.MyPlugin" key='mymacrokey'>
   <parameters>
      <parameter name="prefix" type="string" />
      <parameter name="id" type="int" required="true" />
      <parameter name="mydata" type="string" />
    </parameters>
  </xhtml-macro>
</atlassian-plugin>

My Idea is to use “setMacroJsOverride()” in the resource file “my.js”

AJS.MacroBrowser.setMacroJsOverride("mymacro", {
   fields: {
      string: {
           "prefix": function (param) {
               var parameterField = AJS.MacroBrowser.ParameterFields["string"](param, {});

               var pref;
               try {pref = AJS.MacroBrowser.settings.selectedMacro.params["prefix"]}
               catch (e) {pref = null}

               if(pref != null){
                    console.log("set editable false");
               } else {
                    console.log("let editable true");
               }
               return parameterField;
            }
       }
});

I have two problems:

  1. I have no Idea how to do somthing like “parameterField.setEditable(false)”.
  2. When Prefix is empty string, “prefix” is not saved, and the macro is in the “else” block.
    There must be an other way to detect if the macro is just created or if it is edited. (Or perhaps if it ever has been saved)

Best Regards,

Rainer

I am now one step ahead.

           "prefix": function (param) {
               var parameterField = AJS.MacroBrowser.ParameterFields["string"](param, {});

               if(AJS.MacroBrowser.settings.selectedMacro){
                    console.log("set editable false");
               } else {
                    console.log("let editable true");
               }
               return parameterField;
            }

“AJS.MacroBrowser.settings.selectedMacro” is “undefined” on creating the macro.
So Question 2 is answered by my self.
So I just need to now, how to set “editable false”.

BR
Rainer