0

Symfony 的每一天都是新的一天,但我很喜欢它!今天早上我安装了sfJQueryUIPlugin. 它几乎没有依赖关系并接受 themeRoller 样式。但是,它有两个问题:

[Feature_Request] 无法指定年份范围。默认情况下,它会在字段值中显示围绕年份的 20 年范围。例如。如果字段值为 1993-01-20,则范围为 1983 到 2003。 ??? 有没有人找到出路???

DatePicker 字段为空时不会出现,因此在创建新记录时不会出现。 为了解决这个问题,我尝试使用???在日期输入字段(现在显示为text输入)中设置默认值 $this->setDefault('date_of_birth',date('Y-m-d'));在新记录创建期间是否有人面临选择器的这个问题??????这也是设置默认值的正确方法吗???

提前致谢。

4

1 回答 1

0

要在新注册表单上获取日期选择器,我必须include javascripts在我的表单的 indexSuccess 模板中(我的错)

至于年份范围,我修改了插件文件以包含附加参数

class sfWidgetFormDateJQueryUI extends sfWidgetForm
{
  protected function configure($options = array(), $attributes = array())
  {

    if(sfContext::hasInstance())
     $this->addOption('culture', sfContext::getInstance()->getUser()->getCulture());
    else
     $this->addOption('culture', "en");
    $this->addOption('change_month',  false);
    $this->addOption('change_year',  false);
    $this->addOption('number_of_months', 1);
    $this->addOption('show_button_panel',  false);
    $this->addOption('theme', '/sfJQueryUIPlugin/css/ui-lightness/jquery-ui.css');
    $this->addOption('year_range', '-30:+0');
    parent::configure($options, $attributes);
  }

  public function render($name, $value = null, $attributes = array(), $errors = array())
  {
    $attributes = $this->getAttributes();

    $input = new sfWidgetFormInput(array(), $attributes);

    $html = $input->render($name, $value);

    $id = $input->generateId($name);
    $culture = $this->getOption('culture');
    $cm = $this->getOption("change_month") ? "true" : "false";
    $cy = $this->getOption("change_year") ? "true" : "false";
    $nom = $this->getOption("number_of_months");
    $sbp = $this->getOption("show_button_panel") ? "true" : "false";
    $yrs = $this->getOption("year_range");

    if ($culture!='en')
    {
    $html .= <<<EOHTML
<script type="text/javascript">
    $(function() {
    var params = $.datepicker.regional['$culture'];
    params.changeMonth = $cm;
    params.changeYear = $cy;
    params.numberOfMonths = $nom;
    params.showButtonPanel = $sbp;
    params.yearRange = "$yrs";
    $("#$id").datepicker(params);
    });
</script>
EOHTML;
    }
    else
    {
    $html .= <<<EOHTML
<script type="text/javascript">
    $(function() {
    var params = {
    changeMonth : $cm,
    changeYear : $cy,
    numberOfMonths : $nom,
    showButtonPanel : $sbp,
    yearRange : "$yrs"
        };
    $("#$id").datepicker(params);
    });
</script>
EOHTML;
    }

    return $html;
  }

  public function getStylesheets()
  {...
  }

  public function getJavaScripts()
  {...
  }

}

并将小部件设置为:

$this->widgetSchema['date_of_birth']= new sfWidgetFormDateJQueryUI(array("change_month" => true, "change_year" => true, "theme" => "smoothness/jquery-ui-1.8.custom.css", "year_range" => "-30:+0"));
于 2010-04-22T04:24:03.197 回答