sfJQueryUIPlugin:没有新记录选择器

发布于 2024-08-29 21:48:45 字数 462 浏览 4 评论 0原文

使用 Symfony 的每一天都是新的一天,但我很喜欢它! 今天早上我安装了sfJQueryUIPlugin。它的依赖性非常小接受 themeRoller 样式。但是,它有两个问题:

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

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

提前致谢。

Everyday is a new day with Symfony, but I'm loving it!
This morning I installed the sfJQueryUIPlugin. It has very little dependencies & accepts themeRoller styles. However, it has 2 issues:

[Feature_Request] There is no way to specify the year range. By default, it shows a 20 year range around the year in the field value. eg. if field value is 1993-01-20, the range will be 1983 to 2003.
??? Has anyone found a way out???

The DatePicker does not appear when the field is empty, Thus it does not show up during new record creation.
To solve this, I tried setting up the default value in the date input field (which now appears as a text input) using $this->setDefault('date_of_birth',date('Y-m-d'));
??? Is anybody facing this problem of picker now available during new record creation ???
??? Also is it the right way to set default value ???

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

筑梦 2024-09-05 21:48:53

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

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

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"));

To get the date picker on the new registration form, I had to include javascripts in the indexSuccess template of my form (my fault)

as for the year range, I modified the plugin file to include additional parameter

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()
  {...
  }

}

and setup the widget as:

$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"));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文