Reputation: 57
I am pretty new to the Phalcon PHP framework and the Volt template engine. 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.
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. 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. Is no one using this?
Upvotes: 1
Views: 1841
Reputation: 345
I did it! I used 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.
Upvotes: 1
Reputation: 2039
The date field merely uses HTML5's date field. If you want a date picker, you must use a Javascript date picker library.
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. The list of functions you can use are in the Volt – Using tag helpers documentation page.
Upvotes: 0