Change Comment mandatory
Asked by Andr?W:

Is it possible to make the change comment mandatory for every change to a confluence page? I tested a solution with a jquery macro but it doesn't work correct.

Any idea.  
Thank you.


Answers:
author: Andr?W
body: Okay, i will test and find out, why it doesn't work under Firefox.

The solutiion is a good base for further developement.

Thank you.


author: Michael R_ Wolf
body: Now that the new editor experience does not even allow for a comment, is there a way to use this code to "extend" the "contracted" UI? In effect, this could require a comment even though a comment isn't allowed. It could do this in many ways. A pop-up sounds easiest, but I'm betting there are about 17 other ways to do it.


author: cloud-operations
body: I tried the solution above (server 6.0.4), but the binding didn't work and also preview bypassed the control.

Below is my JS solution which always binds, including when previewing:

```
<script type="text/javascript">
function commentRequired() {
  var buttonID = 'rte-button-publish';
  var textID = 'versionComment';

  // Find the button & text box, only work if they exist
  if (AJS.$('#' + buttonID).length > 0 && AJS.$("#" + textID).length > 0) {
    // Set status at start if necessary
    if (AJS.$('#' + textID).val().length < 10) {
      AJS.$('#' + buttonID).prop('disabled', true);
      AJS.$("#" + textID).css('border-color','#f00')
      AJS.$("#" + textID).css('background-color','#fff4f4')
    }
 
    //If the textbox changes update the status of button and textbox
    AJS.$("#" + textID).keyup(function() {
      if(AJS.$(this).val().length > 9) {
        AJS.$('#' + buttonID).prop('disabled', false);
        AJS.$("#" + textID).css('border-color','')
        AJS.$("#" + textID).css('background-color','')
      } else {
        AJS.$('#' + buttonID).prop('disabled', true);
        AJS.$("#" + textID).css('border-color','#f00')
        AJS.$("#" + textID).css('background-color','#fff4f4')
      }
    });
   }
}

AJS.bind('init.rte', function(a, e) {
  $(e.editor.getWin().parent.document).bind("mode-changed", function() {
    commentRequired();
  }); 
  $(e.editor.getWin().parent.document).bind("iframeAppended", function() {
    commentRequired();
  }); 
});
</script>
```

What I also did was used a Script Runner Script Fragment of type Web Panel to put this into the alt.editor.savebar area only for spaces matching certain criteria.


author: Tori Hunter
body: Does anyone know if there is a newer or improved solution for this? So far in my searching this answer is the one that seems most promising.

Davin Studer, I would like to enable mandatory change comments for a subset of pages within a space I own, but I don't have admin privlidges for the server - is this possible with your solution described above?

We are using version 5.8 server.

Thanks!

comments: author: Davin Studer
body: You would need to be a system admin. Also the JavaScript I provided would affect every page system wide.


author: Tori Hunter
body: Ok, that's what I thought but I appreciate the confirmation and the quick response.


author: Dana Jansen
body: I tried this using IE and Firefox and the save button is NOT disabled. DO I need to restart confluence on the server?


author: Andr?W
body: Okay, we are using Firefox. Now i have tested it with Chrome and IE and it works. But but why not with Firefox? Firefox is our preferred browser. I put debug messages to the script so i could see that the script was called but it was not able to disable the save button.

comments: author: Davin Studer
body: I have tested it on my system with IE9,10,11, current Chrome, and current Firefox and all of them are working. I'm not sure why it isn't working on your system, but the code should work.


author: Andr?W
body: Yes, i tested a solution with jquery, but it doesn't work. Your script doesn't disable the save button, it ist always enabled.

comments: author: Davin Studer
body: What Confluence version are you on and what browser/verion are you using? This works just fine on my environments (Confluence 5.1.3 and 5.2.4).


author: Davin Studer
body: Have you tried something like this? Add it to the custom html in Confluence Admin. I would stick it in the box that says "At end of the BODY".

```
AJS.toInit(function() {	var buttonID = 'rte-button-publish';	var textID = 'versionComment';		if(AJS.$('#' + buttonID).length > 0 && AJS.$("#" + textID).length > 0) {		//Disable save button		AJS.$('#' + buttonID).prop('disabled', true);				//If the text box changes and there is content re-enable the save button		AJS.$("#" + textID).keyup(function() {			if(AJS.$(this).val() !== '') {				AJS.$('#' + buttonID).prop('disabled', false);			} else {				AJS.$('#' + buttonID).prop('disabled', true);			}		});	}});
```

comments: author: Ryan McClay
body: I need something like this that requires body text in confluence. I tried pasting this into the At the end of the BODY section with no changes in behaviour on Chrome on Mac or Safari on Mac. We are running 6.3.3. Do we need to restart confluence after adding Custom HTML? I wouldn't think so.


author: Davin Studer
body: Did you put it inside script tags? If not you need to do that for it to work.

```
<script type="text/javascript">
AJS.toInit(function() {
    var buttonID = 'rte-button-publish';
    var textID = 'versionComment';
 
    if(AJS.$('#' + buttonID).length > 0 && AJS.$("#" + textID).length > 0) {
? ??? ??//Disable save button
? ??? ??AJS.$('#' + buttonID).prop('disabled', true);
 
? ??? ??//If the text box changes and there is content re-enable the save button
? ??? ??AJS.$("#" + textID).keyup(function() {
? ??? ??? ??if(AJS.$(this).val() !== '') {
? ??? ??? ??? ??AJS.$('#' + buttonID).prop('disabled', false);
? ??? ??? ??} else {
? ??? ??? ??? ??AJS.$('#' + buttonID).prop('disabled', true);
? ??? ??? ??}
? ??? ??});
? ??}
});
</script>
```


author: Davin Studer
body: Oh, wait ... Also since they have changed how the editor work you now have to bind to it when it is initialized. It used to be that the page would reload for editing, but not anymore. Here is an updated version for newer versions of Confluence.

```
<script type="text/javascript">AJS.toInit(function(){    AJS.bind('init.rte-control', function(){        var buttonID = 'rte-button-publish';        var textID = 'versionComment';                if(AJS.$('#' + buttonID).length > 0 && AJS.$("#" + textID).length > 0) {            //Disable save button            AJS.$('#' + buttonID).prop('disabled', true);                        //If the text box changes and there is content re-enable the save button            AJS.$("#" + textID).keyup(function() {                if(AJS.$(this).val() !== '') {                    AJS.$('#' + buttonID).prop('disabled', false);                } else {                    AJS.$('#' + buttonID).prop('disabled', true);                }            });        }    });});</script>
```


author: Ryan McClay
body: Thanks for this. No I hadn't done the script tags. Unfortunately, this still doesn't seem to be disabling the publish button?


author: Davin Studer
body: Did you also see that I updated the code right above your latest reply? I changed it to take into account the newer way that the editor is initialized.


author: Ryan McClay
body: Yes, but unfortunately it didn't seem to make a difference.

Just to be sure, I put that in the Custom HTML at the end of the body. I did not restart confluence. Here is a screenshot.![Screen Shot 2017-11-07 at 9.47.34 AM.png](https://community.atlassian.com/t5/image/serverpage/image-id/8972iD10230DB64796B8C/image-size/large?v=v2&px=999 "Screen Shot 2017-11-07 at 9.47.34 AM.png")


author: Davin Studer
body: Hmmm ... It works on my install 6.4.2. using the code above. If you open up your browser's developer tools (F12) do you see any JavaScript errors in the console ... especially when you enter edit mode.


author: Ryan McClay
body: Don't know why I didn't think of that. Not seeing any of the code show up. There is a javascript section earlier in the page, but I'm assuming you can have more than 1 code section in the body?

![Screen Shot 2017-11-07 at 1.05.32 PM.png](https://community.atlassian.com/t5/image/serverpage/image-id/8994i0BAE4573AFA0DB27/image-size/large?v=v2&px=999 "Screen Shot 2017-11-07 at 1.05.32 PM.png")


author: mcclay
body: OK, I'm stupid. The code is working EXACTLY as its supposed to. HOWEVER, what I was wanting was something slightly different. I was wanting to require body content in every post before the publish button became available. How can this code be modified to do that?


author: RambanamP
body: as of now this is not feasible in confluence and already submitted request to implement this @ <https://jira.atlassian.com/browse/CONF-6373>


author: Andr?W
body: Has nobody a good idea for this problem or maybe a link to a good workaround?