Creating a Simple Checkbox Macro

I’m a former Confluence user, and one feature that I used a lot in Confluence was their checkbox macro that could be placed anywhere in a document. Unfortunately, when I imported my Confluence data into XWiki the converter changed all of the clickable Confluence checkboxes into static characters.

With this in mind, I am trying to create a very simple XWiki macro that will just create a checkbox and remember the checked/unchecked state. I created a custom macro that creates a checkbox using a built-in XWiki HTML Macro, but I couldn’t find a way to save the checkbox state. Any suggestions on how to do this?

Hello,

Two possible designs, from the top of my head, as a starting point.

If you want the checkbox to be checked only when editing a document {{checkbox checked='true'/}} should be enough.

If you want the checkbox to be checked also in view mode, you’ll need to:

  • Generate a unique ID for each checkbox
  • Save the checked checkbox IDs in an XObject in the document

In both cases, you’ll probably need some javascript to dynamically change the state of the document.

Note that you are not the first one to be interested in this feature (for instance, How to make dynamic checkbox for Xwiki?). So if you feel like it, you are encouraged to share the result as a contrib extension.

Hope that helps,
Manuel

The best IMO is to add an XObject to the document (one or several depending on how many usage of the macro you do in the page). See Data Model (XWiki.org)

Since you mentioned converting from Confluence, note that there’s a paying extension that helps convert macros from Confluence if you’e interested: https://store.xwiki.com/xwiki/bin/view/Extension/ProMacros/. At first glance it doesn’t seem to offer a checkbox macro though.

Another idea would be to check https://extensions.xwiki.org/xwiki/bin/view/Extension/Todo%20Macro and look at the code (probably just wiki pages containing script). This extension is old though.

Hope it helps

1 Like

Thank you for the suggestions here. I have determined that @vmassol’s recommendation of the Todo Macro will fulfill my current requirements. I also appreciate the design suggestions and links to XWiki documentation - I may end up leveraging them to aid my transition from Confluence.

Hi @spaceman, I’ve written a macro that does what you want - I’ve wanted it, too, for quite some time. I’d be happy to share.

I’d be curious to see it.

@pdwalker Can I post the xar file containing the addons and the event listener here?

I have no idea. You can always try.

Well, you can’t upoad XAR files, so I created a Github repository. You will find the macro at github.com/jmiba/XWiki-Checkboxed-Task-Macro.

2 Likes

Hi @jmiba. Thank you for posting this macro. I’ll install it in my instance and give it a try as soon as I can.

I cannot test it yet as there is a problem in 14.10.2 where the ckeditor options don’t appear in the administration UI.

About this, FYI, there’s a workaround in the jira issue: Loading...

yes, I saw that, but I don’t want to monkey around with object editing. I’ll wait for the fix.

I create enough problems on my own in my xwiki installation that I have to repair. No sense in taking extra chances.

You should be able to use both macros anyway. In the CKEditor, click on the plus sign in the menu and search for the macros task with checkbox and task report.

1 Like

When I try to import the xar file, I get the following error in my catalina.out file

[2023-01-06 10:02:41] [info] 2023-01-06 10:02:41,280 [http-nio-127.0.0.1-8080-exec-5 - http://info.quagmyre.com/xwiki/bin/get/XWiki/XWikiPreferences?xpage=packagedescriptor&package=CheckboxedTask%20Macro.xar] ERROR c.x.x.XWiki - Error while evaluating velocity template [packagedescriptor.vm]
[2023-01-06 10:02:41] [info] org.xwiki.rendering.RenderingException: Failed to execute renderer
(deleted)
[2023-01-06 10:02:41] [info] Caused by: org.xwiki.rendering.RenderingException: Failed to evaluate template with id [/templates/packagedescriptor.vm]
(deleted)
[2023-01-06 10:02:41] [info] Caused by: org.xwiki.velocity.XWikiVelocityException: Failed to evaluate content with namespace [/templates/packagedescriptor.vm]
(deleted)
[2023-01-06 10:02:41] [info] Caused by: org.apache.velocity.exception.MethodInvocationException: Invocation of method ‘toTree’ in class org.xwiki.model.script.ModelScriptService threw exception java.lang.NullPointerException at /templates/packagedescriptor.vm[line 47, column 36]
(deleted)
[2023-01-06 10:02:41] [info] Caused by: java.lang.NullPointerException: null

I managed to import the XAR in XWiki 14.10.2 without any issue, in the jetty distribution.
image

1 Like

I haven’t had this problem. Just imported the xar.file unpacked from the zip-download into a fresh 14.10.2 subwiki and also into a 13.10.6 LTS subwiki in the XWiki cloud.

Great. Does the CheckboxedTaskListener work in your wiki? I.e., are xobjects added to your pages when you insert checkboxed tasks?

I tried again in a second 14.10.2 installation I have on another server and I get the exact same error message.

I must have done something wrong with my installations.

Yes, it seems to work fine.

2 Likes