I think there is a bug in the widget code that is causing duplicate values to be saved to the RRULE, and I think its because this loop is used multiple times to set default values on the widget:

    _.each(RRule.DAYCODES, function (element, index) {
        var d = RRule[element];
        tmpl += '<label class="inline">';
        tmpl += '<input type="checkbox" name="byweekday" value="' + d.weekday + '" />';
        tmpl += RRule.DAYNAMES[index] + '</label>';
      });

This loops through and sets default values. If I create a node and set a date, lets say I choose Weekly, and pick a few days and save. The first save is fine.

When I go back to edit the node, the RRULE day values are now duplicated - its setting the MONTHLY values and using them in the RRULE creation as well, even though MONTHLY is not selected. This does not seem to affect the date creation, but does impact the saved RRULE information.

Where the widget code is generating the RRULE, it needs to ensure it is only pulling the entered values from the currently active occurrence.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kevinquillen created an issue. See original summary.

kevinquillen’s picture

Still looking for a way to fix this - but it can be worked around for now if you filter duplicate values out of the array of weekday items:

 _getRRule: function () {
      //modified from rrule/tests/demo/demo.js
      //ignore 'end', because it's part of the ui but not the spec
      var values = this._getFormValues($(this.element).find('select, input[class!="end-radio"]'));
      var options = {};

      var weekdays = values.byweekday;

      values.byweekday = weekdays.filter(function(item, pos, self) {
        return self.indexOf(item) == pos;
      });

This turns the byweekday item from [0, 2, 4, 0, 2, 4] to just [0, 2, 4] which fixes the UI output in the widget and on the frontend (where the RRULE is displayed in human readable form) and also corrects the RRULE value stored in the database. I believe the bug is in how the values are initially fetched - only the inputs from the currently selected occurrence value should be fetched.

jmuzz’s picture

This does not seem to affect the date creation

It does if you try to uncheck one of the weekdays while editing. There's no way to prevent it from adding in the originally selected days even if you uncheck the boxes for them, and the boxes will be checked again if you try to re-edit the item again after.

kevinquillen’s picture

Yeah, now I see where that happens. So while this seemed to work in one case, it fails when you have a date field that can have multiple delta values. (different day/time schedules within the same event). With the duplicates filtered out, it works in some cases, but not all cases.

Is there any reason this widget has to be like 800 lines of jQuery? It makes it really hard to debug and process.

jmuzz’s picture

You are correct, simply removing duplicate values is not sufficient... There could be different values checked in weekly and monthly and they would all be added. I realized this after creating another ineffective workaround. Oh well... I foresee a solution arising next week or sooner.

SocialNicheGuru’s picture

Status: Active » Needs review
blasvicco’s picture

kevinquillen’s picture

This patch seems to work - I only tested it with weekly so far (my main use case). However I noticed one bug.

a

If you save a node and edit it, then uncheck "Repeat" but then check it back on - the widget UI has your last saved values pre-selected. However, it does not save these values back at all. If you were to recheck the options that are already selected, then it would work.

kevinquillen’s picture

Heres another bug... the monthly widget suffers from the same issues, you can see duplicate values in the screenshot.

First, checking off every week option causes the widget to display:

=> TypeError: Cannot read property 'n' of undefined

in the summary area. I am not sure what that means, but this option in the widget is pretty confusing. I want to show this event and it happens monthly, what are these week options? Every other week style option? There is a lot to unpack there, I just wanted to set an event to run every month for six months, two days every week. Perhaps "All month" and "every other week" could be broken out into two new options, but that can be done for a UX feature issue later.

At the same time, selecting week options doubles up on the day values, and vice versa. You can see that in the screenshot.

f

blasvicco’s picture

FileSize
1.98 KB

New patch.
In order to avoid the use of the same field name for the two select list for week days, I renamed as 'byweekday-pos' in the first patch without realize that there was another field with that name too.
So, in this new patch I renamed as 'byweekday-month', also I added cleaning input values in '_getRRule' method depending the frequency (values['freq']), for example, we don't need to set 'values['byweekday']' if frequency is not monthly or weekly.

https://www.drupal.org/files/issues/date_recur-weekday_duplication-29453...

joelpittet’s picture

Version: 8.x-1.0-alpha5 » 8.x-1.x-dev
SocialNicheGuru’s picture

Status: Needs review » Needs work

I don't seem to have a date_recur/assets folder in the 1.0 version

dpi’s picture

Project: Recurring Dates Field » Interactive widget for Recurring Dates Field
Version: 8.x-1.x-dev »
jacobbell84’s picture

Status: Needs work » Needs review
FileSize
1.96 KB

Quick reroll to support the new javascript paths in 1.0

imclean’s picture

Version: » 8.x-2.x-dev

Applied #14 manually to 8.x-2.x-dev and the widget now correctly updates the RRULE.

tasc’s picture

#14 works for me with 8.x-2.0-alpha1

jds1’s picture

Works for me too! Marking as RTBC.

jds1’s picture

Status: Needs review » Reviewed & tested by the community
jds1’s picture

Status: Reviewed & tested by the community » Needs work

You know, after some more testing I'm finding that the default checkbox selected is the wrong day of the week. RRule output is matching though, and nothing is messed up there. I'm going to try and figure this out/amend the patch if I can unless someone beats me to it. Anyone else having this issue?

electrokate’s picture

@if-jds Did you end up making a patch? I am going to have to do the same.

jds1’s picture

@electrokate – I was able to get the day of week issue fixed with a patch from here https://www.drupal.org/project/date_recur_interactive/issues/2902733. Hope this helps!

electrokate’s picture

@if-jds thank you so much! I don't know how I missed that!! I really appreciate your response! :)

jenniferhoude’s picture

Patch #14 works for me. Can we please add this to the next release.

imclean’s picture

Status: Needs work » Needs review