PHP Allow date function on a repeat

davez

Member
I've got a repeatable group with a date element that uses the PHP Allow date function, that uses AJAX and 'watches' the previous element in the group. It works fine for the first repeat, but in subsequent repeats, it pulls from the first group element in the watch list. Here's the code from the PHP Allow date function in the date element:

Code:
$db = JFactory::getDBO();
$input = JFactory::getApplication()->input;
$site_id = JArrayHelper::getValue($data, 'wic_itinerary___site_id_raw', 0);
$ajax_site_id = $input->get('v', $id);
$site_id = $ajax_site_id;
$query = "SELECT dates_offered  FROM wic_sites where id = '".$site_id."'" ;
$db->setQuery($query);
$dates_allowed = $db->loadResult();
$dates_allowed  = str_replace(' ', '', $dates_allowed );
$date_array = explode(',', $dates_allowed);
$temp_date = $date_array[0];
$d = DateTime::createFromFormat('Y-m-d', $temp_date);
if ($d && $d->format('Y-m-d') === $temp_date) return $date_array;
Again, it works fine for the first repeat, but with the next added repeat group, the watch element it chooses from is from the first repeat, not from the current one.

I might be asking too much of this feature for it to work with in a repeat. Or maybe there's a variable I can pull the current repeat data from rather than from $input. I'm not finding the current repeat data in $input when I var_dump($input).

Thoughts?
 
Meh.

Yes, it would be possible to fix our code so it would work in repeats, but it'd be kind of a pain in the ass. We do similar things in things like the calc and CDD elements, which have the concept of "observed" elements that trigger AJAX updates, and it's rather fiddly to make it "repeat friendly".

No, it's not something you can fix in your code, as (as is) our date JS code simply won't be sending the data for the observed element in other groups.

If you'd like to upgrade to a Pro sub for a month, I can work on this for you.

-- hugh
 
I figured that would be the case. I'm not sure if it would be worth the bother. For my situation, I think there's a better solution. Thanks for the quick check-in.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top