Change Comment mandatory

AndréW January 9, 2014

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.

10 answers

1 accepted

0 votes
Answer accepted
AndréW February 23, 2014

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.

0 votes
Michael R_ Wolf June 14, 2019

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.

0 votes
cloud-operations June 18, 2018

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.

0 votes
Tori Hunter July 25, 2017

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!

Davin Studer
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 25, 2017

You would need to be a system admin. Also the JavaScript I provided would affect every page system wide.

Tori Hunter July 25, 2017

Ok, that's what I thought but I appreciate the confirmation and the quick response.

0 votes
Dana Jansen July 20, 2014

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

0 votes
AndréW February 5, 2014

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.

Davin Studer
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 5, 2014

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.

0 votes
AndréW February 4, 2014

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

Davin Studer
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 4, 2014

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).

0 votes
Davin Studer
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 28, 2014

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);
			}
		});
	}
});

 

 

Ryan McClay October 30, 2017

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.

Davin Studer
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 30, 2017

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>
Davin Studer
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 30, 2017

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>

 

Ryan McClay October 30, 2017

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

Davin Studer
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 31, 2017

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.

Like Deleted user likes this
Ryan McClay November 7, 2017

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

Davin Studer
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 7, 2017

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.

Ryan McClay November 7, 2017

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

mcclay November 10, 2017

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?

0 votes
RambanamP
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 28, 2014

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

0 votes
AndréW January 28, 2014

Has nobody a good idea for this problem or maybe a link to a good workaround?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events