Not sure really how to ask this one :?
I'm working on a way to input multiple dates in the backend for use in a "realestate" module, so that someone can enter say 50 dates and associate them with a price.
I couldn't find a way to select multiple dates into a field using the default Contao calendar, so I've made a Backend class that allows it - using the calendar from here http://keith-wood.name/datepick.html, and adapting Helmut Schottmüller's multitextWizard http://www.contao.org/extension-list...010009.en.html
Each Wizard row consists of a multiple-dates-picker popup calendar and one (or more) text fields.
This works great except that when you click the little "+" icon to make a new row the calendar won't appear on the field UNTIL the record is saved.
I guess this is because the #id that the calendar needs to instantiate from is not in the sourcecode until save, as javascript is responsible for creating the new rows.
Is it possible to make the calendar "bind" to the field in a new row without saving?
I'm not sure what code I need to post here to show anyone, but heres the main class as it stands
There are 2 javascript files that came from multitextWizard as well.... the same except for name changes.Code:<?php if (!defined('TL_ROOT')) die('You can not access this file directly!'); class RealestatePriceWizard extends Widget { /** * Number of text fields * @var int */ protected $intColumns = 1; /** * Labels for the text fields (count must match $intColumns) * @var array */ protected $arrLabels = array(); /** * Submit user input * @var boolean */ protected $blnSubmitInput = true; /** * Template * @var string */ protected $strTemplate = 'be_widget'; /** * Add specific attributes * @param string * @param mixed */ public function __set($strKey, $varValue) { switch ($strKey) { case 'labels': if (is_array($varValue)) { $this->arrLabels = array_values($varValue); } break; case 'columns': $this->intColumns = $varValue; break; case 'value': $this->varValue = deserialize($varValue); break; case 'mandatory': $this->arrConfiguration['mandatory'] = $varValue ? true : false; break; default: parent::__set($strKey, $varValue); break; } } /** * Generate the widget and return it as string * @return string */ public function generate() { // JQUERY DATEPICKER V2 FROM http://keith-wood.name/datepick.html //ADD NESESSARY JAVASCRIPT TO BACKEND HEAD if (is_array($GLOBALS['TL_JAVASCRIPT'])) { array_insert($GLOBALS['TL_JAVASCRIPT'], 1, array('system/modules/realestate/html/js/realestateprice.js','http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js','system/modules/realestate/html/js/jquery.datepick.js')); }else { $GLOBALS['TL_JAVASCRIPT'] = array('system/modules/realestate/html/js/realestateprice.js','http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js','system/modules/realestate/html/js/jquery.datepick.js'); } //ADD NESESSARY CSS TO BACKEND HEAD if (is_array($GLOBALS['TL_CSS'])) { array_insert($GLOBALS['TL_CSS'], 1, 'system/modules/realestate/html/jquery.datepick.css'); }else { $GLOBALS['TL_CSS'] = array('system/modules/realestate/html/jquery.datepick.css'); } $arrButtons = array('rnew','rcopy', 'rup', 'rdown', 'rdelete'); $strCommand = 'cmd_' . $this->strField; $emptyarray = array(); for ($i = 0; $i < $this->intColumns; $i++) array_push($emptyarray, ''); // Change the order if ($this->Input->get($strCommand) && is_numeric($this->Input->get('cid')) && $this->Input->get('id') == $this->currentRecord) { $this->import('Database'); switch ($this->Input->get($strCommand)) { case 'rnew': array_insert($this->varValue, $this->Input->get('cid') + 1, array($emptyarray)); break; case 'rcopy': $this->varValue = array_duplicate($this->varValue, $this->Input->get('cid')); break; case 'rup': $this->varValue = array_move_up($this->varValue, $this->Input->get('cid')); break; case 'rdown': $this->varValue = array_move_down($this->varValue, $this->Input->get('cid')); break; case 'rdelete': $this->varValue = array_delete($this->varValue, $this->Input->get('cid')); break; } $this->Database->prepare("UPDATE " . $this->strTable . " SET " . $this->strField . "=? WHERE id=?") ->execute(serialize($this->varValue), $this->currentRecord); $this->redirect(preg_replace('/&(amp;)?cid=[^&]*/i', '', preg_replace('/&(amp;)?' . preg_quote($strCommand, '/') . '=[^&]*/i', '', $this->Environment->request))); } // Make sure there is at least an empty array if (!is_array($this->varValue) || !$this->varValue[0]) { $this->varValue = array($emptyarray); } // put JQUERY DATEPICKER into no-conflict mode and make available to fields of id #multiPrice_0 etc http://keith-wood.name/datepick.html $return .=' <script type="text/javascript"> $j = jQuery.noConflict(); </script>'; // Begin table $return .= '<div class="tl_realestatepricewizard"> <table cellspacing="0" cellpadding="0" class="tl_modulewizard" id="ctrl_'.$this->strId.'" summary="RealestatePrice wizard" ' . $this->getAttributes() . '>'; $return .= '<thead>'; $return .= ' <tr>'; // Add labels for ($h=0; $h<$this->intColumns; $h++) { $return .= '<th style="padding-right: 7px;">' . ((array_key_exists($h, $this->arrLabels)) ? $this->arrLabels[$h] : "") . '</th>'; } $return .= '<th style="white-space:nowrap;"></th> </tr></thead>'; $return .= '<tbody>'; // Add rows for ($i=0; $i<count($this->varValue); $i++) { $return .= ' <tr>'; //*********************************************************** // Add cells dates,amount,class for ($k=0; $k<$this->intColumns; $k++) { $return .= '<td style="padding-right: 7px;">'; //class="tl_text" style="width: 150px; padding-right: 2px;" if($k == 0) { $return .= '<input type="hidden" name="'.$this->strId.'['.$i.']['.$k.']" id="multiPrice_'.$i.'" value="'.specialchars($this->varValue[$i][$k]).'"' . ' /><span>[img]system/modules/realestate/html/calendar-icon.gif[/img]</span> <script type="text/javascript"> <![CDATA[//><!-- $j(\'#multiPrice_'.$i.'\').datepick({ dateFormat: \'@\', multiSelect: 999, monthsToShow: 3, showTrigger: \'#multiPriceButton_'.$i.'\'}); //--><!]]> </script>'; }else { $return .= '<input type="text" name="'.$this->strId.'['.$i.']['.$k.']" class="tl_text" style="width: 150px; padding-right: 2px;" value="'.specialchars($this->varValue[$i][$k]).'"' . ' />'; } $return .= '</td>'; } $return .= ' <td style="white-space:nowrap; width: 110px;">'; //*************************************************************** // Add row buttons foreach ($arrButtons as $button) { $return .= 'strTable][$button][0]).'" onclick="RealestatePrice.realestatepriceWizard(this, \''.$button.'\', \'ctrl_'.$this->strId.'\'); return false;">'.$this->generateImage(substr($button, 1).'.gif', $GLOBALS['TL_LANG'][$this->strTable][$button][0], 'class="tl_realestatepricewizard_img"').' '; } $return .= '</td> </tr>'; } return $return.' </tbody> </table> </div>'; } } ?>
[attachment=0:3opqbjn0]prices.jpg[/attachment:3opqbjn0]
The attachment demonstrates selecting all Fri/Sat over 3 months into a hidden field via an image.... all good except no calendar appears on new rows until after "save".
I also can't figure why my calendar-button image appears twice (left works, right doesn't!)
Bookmarks