1

For some reason we're getting a null set of data when the {if segment_3 == "week"} evaluates to true and its code is run:

// Base template

{if segment_3 == "day"} {!-- This works. --}
    {embed="calendar/event_landing" range_start="{segment_4}/{segment_5}/{segment_6}" range_end="{segment_4}/{segment_5}/{segment_6}"}
{/if}

{if segment_3 == "week"} {!-- This DOES NOT work. --}
    {embed="calendar/event_landing" range_start="{segment_4}/{segment_5}/{segment_6}" range_end="+1 week"}
{/if}

{if segment_3 == "month"} {!-- This works. --}
    {embed="calendar/event_landing" range_start="{segment_4}/{segment_5}/{segment_6}" range_end="+1 month"}
{/if}

// event_landing template

{exp:calendar:cal date_range_start="{embed:range_start}" date_range_end="{embed:range_end}" pad_short_weeks="n"}
    ...show events...
{/exp:calendar:cal}

In our ajax call, we're changing the segments before we send them so all single digits receive preceeding 0s.

// JS

var s_2 = {segment_2} + "", // M
    s_3 = {segment_3} + "", // D
    s_4 = {segment_4} + ""; // Y

if (s_2.length == 1) { s_2 = "0" + s_2; }
if (s_3.length == 1) { s_3 = "0" + s_3; }

// Render the AJAX url before calling it
ajaxTarget = "/calendar/ajax/" + selectedRange + "/" + s_2 + "/" + s_3 + "/" + s_4 + "/";

For an example, when the value of our ajaxTarget var is

/calendar/ajax/week/01/02/2014/

the event data for the next 7 days is returned just fine, but if we change the value of 02 to 27, resulting in

/calendar/ajax/week/01/27/2014/

no data is returned!

Please note that we've also tried using +7 days with the same results.

Any help on this would be appreciated~


EDIT 1:

I think I figured out the reason, but I don't know how to fix it:

I added this little bit of debug to the event_landing page:

<script type="text/javascript">
    var s4 = {segment_4} + "",
        s5 = {segment_5} + "",
        s6 = {segment_6} + "";

    console.log("/" + s4 + "/" + s5 + "/" + s6);
</script>

It's showing that the data is /1/20/2014, but this shouldn't be happening because we're adding (and checking) preceeding zeros before this is reached; they're just not showing up. Right before the $.ajax(...) call, the the log shows the ajaxTarget as /calendar/ajax/week/01/20/2014/, so it's being changed during the request somehow :(

5
  • For completeness, can you tell us what version of Calendar and EE you are using? Also, have you tried the calendar code without any javascript/ajax to see if that works at least? Finally, why go to the trouble of adding/removing 0 through javascript when you could use 0-containing segments directly?
    – Solspace
    Jan 3 '14 at 22:11
  • Can you also show us your full js/ajax code? What is triggering the ajax, by the way? Where is the js code placed?
    – Solspace
    Jan 3 '14 at 22:39
  • Thanks for your interest in this, but i tracked it down to a bug in EE. Essentially, zero-padded numbers don't retain their padding, and trying to add those zeros back is really difficult. Here's my other thread about it: expressionengine.stackexchange.com/questions/18062/… Jan 8 '14 at 1:26
  • Ignoring js/ajax for a moment, you should be able to use Calendar with zero-padded numbers as segments in the URL, eg. /calendar/events/2014/01/07. I'm still wondering if something can't be tweaked in your javascript. If you can show more of the script, as well as tell us what is triggering the ajax, maybe there's a simple (or different) solution to your issue.
    – Solspace
    Jan 8 '14 at 5:34
  • Have you also tried using this ajax script code: support.solspace.com/solution/categories/115922/folders/190597/…. You might need to tweak it for your needs, though.
    – Solspace
    Jan 8 '14 at 5:35
1

If this is your URL:

/calendar/ajax/week/01/02/2014/

Then this part of your code is incorrect because it's calling the wrong segments:

var s_2 = {segment_2} + "", // M
    s_3 = {segment_3} + "", // D
    s_4 = {segment_4} + ""; // Y

Should be:

var s_2 = {segment_4} + "", // M
    s_3 = {segment_5} + "", // D
    s_4 = {segment_6} + ""; // Y
1
  • That's kind of you to point out but that's actually referencing the segments for the current page URL, whereas the latter 4/5/6 reference the segments in the AJAX GET request and I simply omitted that fact. The end-user never sees a redirect to /calendar/ajax/week/.../, simply /calendar/MM/DD/YYYY/ Jan 2 '14 at 21:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.