开发者

Calendar drop down bug

开发者 https://www.devze.com 2023-04-05 05:07 出处:网络
This should be quite simple but I can`t fix it :/ I am using a component that displays a list of months, the upcoming 12 to be exact. However, the year does not change to 2012 when past December.

This should be quite simple but I can`t fix it :/

I am using a component that displays a list of months, the upcoming 12 to be exact. However, the year does not change to 2012 when past December.

See here: http://protekco.com/index.php/en/reserv开发者_如何学运维ation.html

And the code that calls it:

        echo AHtml::getMonthsSelect('imonth', (int) $month, $year, $currentMonth, $currentYear, $config->calendarDeepMonth, 'onchange="Calendars.monthNavigation(this.value)"'); ?>

The $currentYear is the actual year variable that is presented on the site. I basically need someway to add +1 if we are past the end of the year. Any ideas?

Thanks!

Edit: here is the months array:

 function getMonthsSelect($name, $selectedMonth, $selectedYear, $month, $year, $deep, $attribs = '')
{
    $months = array(1 => JText::_('January') , 2 => JText::_('February') , 3 => JText::_('March') , 4 => JText::_('April') , 5 => JText::_('May') , 6 => JText::_('June') , 7 => JText::_('July') , 8 => JText::_('August') , 9 => JText::_('September') , 10 => JText::_('October') , 11 => JText::_('November') , 12 => JText::_('December'));

    $stop = $month + $deep;
    for ($i = $month; $i < $stop; $i ++)
        $arr[] = JHTML::_('select.option', ($key = (! ($k = $i % 12) ? 12 : $k)) . ',' . ($y = (floor(($i - $month) / 12) + $year)), ($months[$key] . '/' . $y));

    return JHTML::_('select.genericlist', $arr, $name, $attribs, 'value', 'text', $selectedMonth . ',' . $selectedYear);
}

Edit 3: Final solution:

function getMonthsSelect($name, $selectedMonth, $selectedYear, $month, $year, $deep, $attribs = '')
{
    $months = array(1 => JText::_('January') , 2 => JText::_('February') , 3 => JText::_('March') , 4 => JText::_('April') , 5 => JText::_('May') , 6 => JText::_('June') , 7 => JText::_('July') , 8 => JText::_('August') , 9 => JText::_('September') , 10 => JText::_('October') , 11 => JText::_('November') , 12 => JText::_('December'));

    $stop = $month + $deep;
    $wheremonth = 12 - $month;
    for ($i = $month; $i < $stop; $i ++, $wheremonth--)

    if ($wheremonth >= 0) {
        $arr[] = JHTML::_('select.option', ($key = (! ($k = $i % 12) ? 12 : $k)) . ',' . ($y = (floor(($i - $month) / 12) + $year)), ($months[$key] . '/' . $y));
        }
        else {            $arr[] = JHTML::_('select.option', ($key = (! ($k = $i % 12) ? 12 : $k)) . ',' . ($y = (floor(($i - $month) / 12) + $year+1)), ($months[$key] . '/' . $y));
        }
    return JHTML::_('select.genericlist', $arr, $name, $attribs, 'value', 'text', $selectedMonth . ',' . $selectedYear);

        }


Not sure how the inputs are working here, but you have next month and previous month. You can implement a counter variable that adds when you hit next and subtracts when you hit previous. So something like:

$i = 1;

function datetracker() {

if($nextbtnclicked = true) {
     $i++;
} elseif($prevbtnclicked = true) {
     $i--;
}

if($i == 13) {
     $i = 1;
     $currentYear += 1;
}
}

I'm just using sample variables, but you can implement the counter in the Javascript and do the login in JS.

EDIT: That code actually looks right. Don't know why it's not working, but try something like this.

function getMonthsSelect($name, $selectedMonth, $selectedYear, $month, $year, $deep, $attribs = '') 
{ 
    $months = array(1 => JText::_('January') , 2 => JText::_('February') , 3 => JText::_('March') , 4 => JText::_('April') , 5 => JText::_('May') , 6 => JText::_('June') , 7 => JText::_('July') , 8 => JText::_('August') , 9 => JText::_('September') , 10 => JText::_('October') , 11 => JText::_('November') , 12 => JText::_('December')); 

    $stop = $month + $deep;
    $newyear = false;
    for ($i = $month; $i < $stop; $i ++) {

        if($newyear) {
        $arr[] = JHTML::_('select.option', ($key = (! ($k = $i % 12) ? 12 : $k)) . ',' . ($y = (floor(($i - $month) / 12) + $year + 1)), ($months[$key] . '/' . $y));
         $newyear = false;
        } else {
        $arr[] = JHTML::_('select.option', ($key = (! ($k = $i % 12) ? 12 : $k)) . ',' . ($y = (floor(($i - $month) / 12) + $year)), ($months[$key] . '/' . $y));

        }
     if($i == 12) { $newyear = true; }
     }

    return JHTML::_('select.genericlist', $arr, $name, $attribs, 'value', 'text', $selectedMonth . ',' . $selectedYear); 
} 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号