Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 48 additions & 2 deletions src/pat/recurrence/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,54 @@ Show the recurrence widget.

## Example

<textarea class="pat-recurrence"></textarea>
### Recurrence without additional start feature

<label>Recurrence start date:
<input name="start-1" type="date" value="2026-01-01"/>
</label>
<label>Recurrence:
<textarea
class="pat-recurrence"
data-pat-recurrence='{
"startField": "[name=start-2]"
}'></textarea>
</label>

```html
<textarea
class="pat-recurrence"
data-pat-recurrence='{
"startField": "[name=start-2]"
}'
></textarea>
```

### Recurrence with additional start feature

Note: adding additional start dates is a feature of the specification but is
not supported by a number of external tools, like Google Calendar, Microsoft
Outlook or Gnome Calendar.
Therefore, this feature is disabled by default.
However, you can enable it with the `hasAdditionalDates` feature.

<label>Recurrence start date:
<input name="start-2" type="date" value="2026-01-01"/>
</label>
<label>Recurrence:
<textarea
class="pat-recurrence"
data-pat-recurrence='{
"startField": "[name=start-2]",
"hasAdditionalDates": true
}'></textarea>
</label>

```html
<textarea class="pat-recurrence"></textarea>
<textarea
class="pat-recurrence"
data-pat-recurrence='{
"startField": "[name=start-2]",
"hasAdditionalDates": true
}'
></textarea>
```
12 changes: 7 additions & 5 deletions src/pat/recurrence/recurrence.js
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,6 @@ const RecurrenceInput = function (conf, textarea) {
}

occurrenceDiv = element.find(".rioccurrences");
occurrenceDiv.hide();

const year = startdate.getFullYear();
const month = startdate.getMonth() + 1;
Expand Down Expand Up @@ -811,11 +810,11 @@ const RecurrenceInput = function (conf, textarea) {
.find(".rioccurrences .action a.rdate")
.on("click", occurrenceDelete);
}
// Show the new div
occurrenceDiv.show();
},
error: function (jqXHR, textStatus) {
alert(textStatus);
error: function () {
occurrenceDiv[0].innerHTML = `
<div class="alert alert-warning">${conf.localization.error_load_occurrences}</div>
`;
},
});
}
Expand Down Expand Up @@ -1377,6 +1376,8 @@ export default Base.extend({
monthly: "Monthly",
yearly: "Yearly",
},

error_load_occurrences: "Cannot load the occurrences preview.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so the translated strings are all provided via the plone.formwidget.recurrence template markup right? This should be implemented there too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

},

readOnly: false,
Expand All @@ -1392,6 +1393,7 @@ export default Base.extend({
ributtonExtraClass: "",

// INPUT CONFIGURATION
hasAdditionalDates: false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me allowAdditionalDates woud make more sense, as its in line with the z3c.form widget property.

Copy link
Member Author

@thet thet Jan 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed to hasAdditionalDates as we already have hasRepeatForeverButton. But is there already a z3c.form widget property which is named allowAdditionalDates? I thought that was introduced in plone/plone.formwidget.recurrence#66

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No there isn't. I just wanted to be them in sync.

hasRepeatForeverButton: true,

// JQUERY TEMPLATE NAMES
Expand Down
67 changes: 67 additions & 0 deletions src/pat/recurrence/recurrence.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,71 @@ describe("Recurrence", function () {
).toEqual("none");
expect(document.querySelector("div.riform").style.display).toEqual("none");
});

it("Adds a warning, if the occurrences preview cannot be loaded.", async function () {
// Without any test mock server, the occurrences preview cannot be loaded.
document.body.innerHTML = `
<input name="start" type="date" value="2026-01-01" />
<textarea class="pat-recurrence"
data-pat-recurrence='{
"startField": "[name=start]"
}'
></textarea>
`;

registry.scan(document.body);
await utils.timeout(1);

const edit_btn = document.querySelector("[name=riedit]");
edit_btn.click();

const occurrences_preview = document.querySelector(
".rioccurrences .alert-warning",
);
expect(occurrences_preview).toBeTruthy();
expect(occurrences_preview.textContent.trim()).toBe(
"Cannot load the occurrences preview.",
);
});

it("Initializes without the additional dates feature.", async function () {
document.body.innerHTML = `
<input name="start" type="date" value="2026-01-01" />
<textarea class="pat-recurrence"
data-pat-recurrence='{
"startField": "[name=start]"
}'
></textarea>
`;

registry.scan(document.body);
await utils.timeout(1);

const edit_btn = document.querySelector("[name=riedit]");
edit_btn.click();

const add_occurrence = document.querySelector(".modal .riaddoccurrence");
expect(add_occurrence).toBeFalsy();
});

it("Initializes with the additional dates feature.", async function () {
document.body.innerHTML = `
<input name="start" type="date" value="2026-01-01" />
<textarea class="pat-recurrence"
data-pat-recurrence='{
"startField": "[name=start]",
"hasAdditionalDates": true
}'
></textarea>
`;

registry.scan(document.body);
await utils.timeout(1);

const edit_btn = document.querySelector("[name=riedit]");
edit_btn.click();

const add_occurrence = document.querySelector(".modal .riaddoccurrence");
expect(add_occurrence).toBeTruthy();
});
});
2 changes: 2 additions & 0 deletions src/pat/recurrence/templates/form.xml
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@
<div class="rioccurrences"></div>

<div class="rioccurrencesactions">
<% if (hasAdditionalDates === true) { %>
<h6><strong><%= localization.addDate %></strong></h6>
<div class="riaddoccurrence ">
<div class="alert alert-danger d-none"></div>
Expand All @@ -299,6 +300,7 @@
<input class="btn btn-sm btn-success" type="button" name="addaction" id="addaction" value="<%= localization.add %>">
</div>
</div>
<% } %>
</div>

<div class="ributtons">
Expand Down