我想在magento日历中禁用多天。我怎么能禁用一天。使用以下代码。但是我想在日历中删除多天,所以问题是disableFunc函数如何返回将被禁用的多天。
Follwing是代码<script type="text/javascript">
//<![CDATA[
Calendar.setup({
inputField : '_dob',
ifFormat : '%m/%e/%y',
button : '_dob_trig',
align : 'Bl',
disableFunc: function(date) {
return date.getDay() === 1; // Sunday is 0, Monday is 1, and so on
},
singleClick : true
});
//]]>
</script>
答案 0 :(得分:0)
/app/code/local/Varien/Data/Form/Element/date.php
在以上位置创建.php文件。以下代码提前两周禁用日期,并将日历提前至最短的可用日期。希望这可以帮助。在我看来,这不是最干净的方式,但它确实有效。
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magentocommerce.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
* @category Varien
* @package Varien_Data
* @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
/**
* Varien data selector form element
*
* @category Varien
* @package Varien_Data
* @author Magento Core Team <core@magentocommerce.com>
*/
class Varien_Data_Form_Element_Date extends Varien_Data_Form_Element_Abstract
{
/**
* Output the input field and assign calendar instance to it.
* In order to output the date:
* - the value must be instantiated (Zend_Date)
* - output format must be set (compatible with Zend_Date)
*
* @return string
*/
public function getElementHtml()
{
$this->addClass('input-text');
$html = sprintf(
'<input name="%s" id="%s" value="%s" %s style="width:110px !important;" />'
.' <img src="%s" alt="" class="v-middle" id="%s_trig" title="%s" style="%s" />',
$this->getName(), $this->getHtmlId(), $this->_escape($this->getValue()), $this->serialize($this->getHtmlAttributes()),
$this->getImage(), $this->getHtmlId(), 'Select Date', ($this->getDisabled() ? 'display:none;' : '')
);
$outputFormat = $this->getFormat();
if (empty($outputFormat)) {
throw new Exception('Output format is not specified. Please, specify "format" key in constructor, or set it using setFormat().');
}
$displayFormat = Varien_Date::convertZendToStrFtime($outputFormat, true, (bool)$this->getTime());
if (Mage::getSingleton('admin/session')->getUser()) {
$html .= sprintf('
<script type="text/javascript">
//<![CDATA[
Calendar.setup({
inputField: "%s",
ifFormat: "%s",
showsTime: %s,
button: "%s_trig",
align: "Bl",
singleClick : true,
weekNumbers: false
});
//]]>
</script>',
$this->getHtmlId(), $displayFormat,
$this->getTime() ? 'true' : 'false', $this->getHtmlId()
);
} else {
$html .= sprintf('
<script type="text/javascript">
//<![CDATA[
// Get current date plus two weeks
var twoWeeks = new Date(+new Date() + (14 * 24 * 60 * 60 * 1000));
Calendar.setup({
inputField: "%s",
ifFormat: "%s",
showsTime: %s,
button: "%s_trig",
align: "Bl",
singleClick : true,
weekNumbers: false,
date: twoWeeks,
disableFunc: function(date) {
// Disable dates with previous years
if (date.getFullYear() < twoWeeks.getFullYear()) {
return true;
} else {
// Disable dates with same year but previous months
if(date.getFullYear() === twoWeeks.getFullYear()) {
if (date.getMonth() < twoWeeks.getMonth()) {
return true;
} else {
// Disable dates with the same month but previous dates
if (date.getMonth() === twoWeeks.getMonth()) {
if(date.getDate() < twoWeeks.getDate()) {
return true;
}
}
}
}
}
}
});
//]]>
</script>',
$this->getHtmlId(), $displayFormat,
$this->getTime() ? 'true' : 'false', $this->getHtmlId()
);
}
$html .= $this->getAfterElementHtml();
return $html;
}
}