[英]Using a datepicker with Phalcon Volt template engine
I am pretty new to the Phalcon PHP framework and the Volt template engine. 我对Phalcon PHP框架和Volt模板引擎还很陌生。 So far I really like it though.
到目前为止,我真的很喜欢。
One thing that I can't figure out however, is how to implement a date picker to a date field. 但是我不知道的一件事是如何对日期字段实现日期选择器。 I have a date field defined as below, but rather than having to manually input a date I would like the user to select a date from a date picker.
我有一个如下定义的日期字段,但是不必手动输入日期,我希望用户从日期选择器中选择一个日期。
<?php echo Tag::dateField(array("finishdate", "size" => 8, "maxlength" => 8, "type" => "date")) ?>
I thought that maybe it would automatically get a date picker if it was defined as a date field, or maybe there was an option somewhere, but I have looked all over internet and I can't find anything. 我以为,如果将它定义为日期字段,也许它将自动获得一个日期选择器,或者某个地方有一个选项,但是我在Internet上四处寻找,找不到任何东西。
I would be very grateful if someone knew how to solve this? 如果有人知道如何解决这个问题,我将不胜感激。
I am also trying to figure out the Volt textArea and I have problems finding any information regarding this as well. 我还试图找出Volt textArea,并且在查找与此有关的任何信息时遇到问题。 I can't seem to get the text area to show as a text box.
我似乎无法使文本区域显示为文本框。 There just seems to be very little information from users regarding Phalcon Volt.
用户提供的有关Phalcon Volt的信息似乎很少。 Is no one using this?
没人使用吗?
I did it! 我做的! I used datepicker ( https://jqueryui.com/datepicker/ ).
我使用了datepicker( https://jqueryui.com/datepicker/ )。 I share with you the code.
我与您分享代码。
Form: 形成:
$fecha = new Text('fecha_final');
$fecha->setLabel('Fecha Final');
$fecha->addValidators(array(
new PresenceOf(array(
'message' => 'Por favor pon una fecha límite'
))
));
$this->add($fecha);
Controller: 控制器:
public function nuevakeywordAction(){
$auth = $this->session->get('auth');
$permiso = $auth['active'];
if($permiso!='A'){return $this->forward('servicios/index');}
$form = new NuevakeywordForm;
if ($this->request->isPost()) {
$trackeable = $this->request->getPost('trackeable', array('string', 'striptags'));
$idcliente = $this->request->getPost('idcliente');
$fecha = $this->request->getPost('fecha');
$keyword = new Keyword();
$keyword->trackeable = $trackeable;
$keyword->cliente_idcliente = $idcliente;
$keyword->fecha_inicial = new Phalcon\Db\RawValue('now()');
$keyword->fecha_final = $fecha;
if ($keyword->save() == false) {
foreach ($keyword->getMessages() as $message) {
$this->flash->error((string) $message);
}
} else {
$this->tag->setDefault('trackeable', '');
$this->tag->setDefault('idcliente', '');
$this->tag->setDefault('fecha', '');
$this->flash->success('Keyword agregada correctamente');
return $this->forward('admin/verkeywords');
}
}
$this->view->form = $form;
}
View: 视图:
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<section class="container animated fadeInUp">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<div id="login-wrapper">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">
Registrar Nueva Keyword
</h3>
</div>
<div class="panel-body">
{{ form('admin/nuevakeyword/', 'id': 'nuevakeywordForm', 'onbeforesubmit': 'return false') }}
<fieldset>
<div class="control-group">
{{ form.label('trackeable', ['class': 'control-label']) }}
<div class="controls">
{{ form.render('trackeable', ['class': 'form-control']) }}
</div>
</div>
<div class="control-group">
{{ form.label('idcliente', ['class': 'control-label']) }}
<div class="controls">
{{ form.render('idcliente', ['class': 'form-control']) }}
</div>
</div>
<div class="control-group">
{{ form.label('fecha_final', ['class': 'control-label']) }}
<div id="datepicker" class="controls">
{{ form.render('fecha_final', ['class': 'form-control']) }}
</div>
</div>
<div class="form-actions">
{{ submit_button('Insertar', 'class': 'btn btn-primary', 'onclick': 'return SignUp.validate();') }}
</div>
</fieldset>
</form>
</div>
</div>
</div>
</div>
</div>
</section>
<script type="text/javascript">
$(function() {
$("#fecha_final").datepicker();
});
</script>
I hope it will help you. 希望对您有帮助。
The date field merely uses HTML5's date field. 日期字段仅使用HTML5的日期字段。 If you want a date picker, you must use a Javascript date picker library.
如果要使用日期选择器,则必须使用Javascript日期选择器库。
As for text areas and text fields, you should use the function text_field()
to create a text field, and text_area()
to create a text area. 对于文本区域和文本字段,应使用函数
text_field()
创建文本字段,并使用text_area()
创建文本区域。 The list of functions you can use are in the Volt – Using tag helpers documentation page. 可以使用的功能列表在Volt –使用标签帮助程序文档页面中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.