Spanish location for yii2-date-picker-widget - datepicker

I am working on the basic template of Yii2. I use the 2amigos yii2-date-picker-widget.
Datepicker is working fine, but it keeps showing me the default language (that is English) instead of Spanish.
As you can see in the code below, the language param is set to 'es':
<?= $form->field($model, 'alta')->widget(
DatePicker::className(), [
'inline' => false,
'clientOptions' => [
'format' => 'yyyy-mm-dd',
'weekStart' => 1,
'todayBtn' => 'linked',
'clearBtn' => true,
'language' => 'es',
'autoclose' => true,
'todayHighlight' => true
]
]);?>
It seems tha the 2amigos Datepicker comes into the proper location whith:
DatePickerLanguageAsset::register($view)->js[] = 'bootstrap-datepicker.' . $this->language . '.min.js';
that means #vendor/bower/bootstrap-datepicker/dist/locales/bootstrap-datepicker.es.min.js, that is an existing file containing my desired spanish location:
!function(a){a.fn.datepicker.dates.es={days:["Domingo","Lunes","Martes","Miércoles","Jueves","Viernes","Sábado","Domingo"],daysShort:["Dom","Lun","Mar","Mié","Jue","Vie","Sáb","Dom"],daysMin:["Do","Lu","Ma","Mi","Ju","Vi","Sa","Do"],months:["Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre"],monthsShort:["Ene","Feb","Mar","Abr","May","Jun","Jul","Ago","Sep","Oct","Nov","Dic"],today:"Hoy",clear:"Borrar",weekStart:1,format:"dd/mm/yyyy"}}(jQuery);
Why this translation is not being applied?
A lot of thanks.

Your translation doesn't work because of wrong syntax, You should move Your language param from 'clientOptions' to top level array:
<?= $form->field($model, 'alta')->widget(
DatePicker::className(), [
'inline' => false,
'language' => 'es',
'clientOptions' => [
'format' => 'yyyy-mm-dd',
'weekStart' => 1,
'todayBtn' => 'linked',
'clearBtn' => true,
'autoclose' => true,
'todayHighlight' => true
]
]);?>

Related

Remove tooltip from kartik/date/datepicker

I use kartik DatePicker in my activeform.
use kartik\date\DatePicker;
My activeform field:
<?= $form->field($model, 'transferred_date')->widget(DatePicker::className(), [
'value' => date('d-M-Y', strtotime('+2 days')),
'options' => ['placeholder' => 'Select date ...'],
'pluginOptions' => [
'format' => 'dd-mm-yyyy',
'todayHighlight' => true
]
])->label('Transferred Date');
?>
When I hover the mouse on calendar icon, it shows a tool tip like this.
I have to remove the tooltip. How can I?
When reading the doc you can read this in the settings:
pickerButton: mixed the calendar picker button configuration - applicable only when type is set to DatePicker::TYPE_COMPONENT_PREPEND or DatePicker::TYPE_COMPONENT_APPEND. This can be one of the following types:
string, if this is a string, it will be displayed as is (and will not be HTML encoded).
boolean, if this is set to false, it will not be displayed.
array, this is the default behavior. If passed as an array, it will be considered as HTML attributes for the picker button addon. The following special keys are recognized:
icon, string the bootstrap glyphicon name/suffix. Defaults to 'calendar'.
title, string|boolean the title to be displayed on hover. Defaults to 'Select date & time'. If this is set to false, it will not be displayed.
So i can say without testing that it should be something like this:
<?= $form->field($model, 'transferred_date')
->widget(DatePicker::className(), [
'type' => DatePicker::TYPE_COMPONENT_PREPEND,
'pickerButton' => ['title' => false],
'value' => date('d-M-Y', strtotime('+2 days')),
'options' => ['placeholder' => 'Select date ...'],
'pluginOptions' => [
'format' => 'dd-mm-yyyy',
'todayHighlight' => true
]
])->label('Transferred Date');
?>
So you missed this in the config:
'type' => DatePicker::TYPE_COMPONENT_PREPEND,
'pickerButton' => ['title' => false],

TYPO3 Inline element appearance configuration partially does not work

I have an own content element on my TCA/Overrides and i have some appearance settings configured. The problem is that i get these settings partially on my backend. This is my code:
$projectOptions = array(
'ak_website' => [
'exclude' => 1,
'label' => 'LLL:EXT:ak_website_base/Resources/Private/Language/locallang.xlf:website.items',
'config' => [
'type' => 'inline',
'foreign_table' => 'ak_website',
'foreign_field' => 'tt_content',
'maxitems' => 999,
'appearance' => [
'useSortable' => 1,
'collapseAll' => 1,
'levelLinksPosition' => 'bottom',
'enabledControls' => [
'info' => TRUE,
'new' => TRUE,
'dragdrop' => TRUE,
'sort' => TRUE,
'hide' => TRUE,
'delete' => TRUE,
'localize' => TRUE,
],
],
],
],
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('tt_content',$projectOptions);
Now, everything works as it suppose to work BUT on the appearance settings the following settings do not work.
useSortable
new
dragdrop
sort
hide
delete
localize
Info works!
The way i see it, everything that has to do with the manipulation, do not work. I might have forgotten to set some rights, or include a TYPO3 function etc. I really have no idea what to do right now. It would be great for future references and for people who might come across the same problem to find the solution here.
Best regards,
Thanks to the TYPO3 community and specifically Carine LAVAL i found my answer.
I needed a sorting column on my database.
How this works:
ak_website.php (TCA)
Add 'sortby' => 'sorting',
<?php
return [
'ctrl' => [
'sortby' => 'sorting',
],
ext_tables.sql
Add this on your table:
sorting int(11) DEFAULT '0' NOT NULL,
And you are all set :)

How to highlight a date(Some other date not the today's date) in Kartik Datepicker

I'm able to highlight current date with 'todayHighlight' => true, but I want to highlight some other date.
You can use this function beforeShowDay as pluginOptions array key.
Here is simple example:
<?= $form->field($model, 'myDate', ['showLabels' => false])->widget(DatePicker::className(), [
'size' => 'sm',
'type' => DatePicker::TYPE_INPUT,
'pluginOptions' => [
'autoclose' => true,
'format' => 'Y-m-d',
'startDate' => date('Y-m-d'),
'endDate' => date('Y-m-d', strtotime('-1 day')),
'weekStart' => 1,
'beforeShowDay' => new \yii\web\JsExpression("function (dates) {
console.log(dates); // List with available dates as date object defined with startDate/endDate (for mor customisations if needed)
return {classes: 'highlight', tooltip: 'Pick this day'};
}
}"),
]
]); ?>
Don't forget to define class (.highlight in this case) in your css.
.highlight{background: #ebf4f8}

language settings in Zend Framework 2 new DateSelect/MonthSelect Form

i have quick questions: i need to set the month dates on my form to English settings; they are curretnly set in Romanian Langugauge
i followed the example set by bakura10 / gist:3705417 and set my dates as such:
$this->add(array(
'type' => 'Zend\Form\Element\DateSelect',
'name' => 'birthDate',
'options' => array(
'label' => 'Date',
'create_empty_option' => true,
'day_attributes' => array(
'data-placeholder' => 'Day',
'style' => 'width: 20%',
),
'month_attributes' => array(
'data-placeholder' => 'Month',
'style' => 'width: 20%',
),
'year_attributes' => array(
'data-placeholder' => 'Year',
'style' => 'width: 20%',
)
)
));
i then set my view helper as such;
echo $this->formDateSelect($this->form->get('birthDate'), IntlDateFormatter::LONG, 'ro_RO');
the problem is that this obviously gives me romanian setting; i dont know where to get the settings for English; i tried this but it does not work;
echo $this->formDateSelect($this->form->get('birthDate'), IntlDateFormatter::LONG, 'en');

How to pre-select a form radio item with Symfony 2?

I'm working on a language choice form:
$currentLocale = "en_US"; // This is indeed sent to the formType
$langs = array(
'fr_FR' => 'fr',
'en_US' => 'en'
);
$builder->add('language', 'language', array(
'choices' => $langs,
'expanded' => true,
'multiple' => false,
'required' => false,
'label' => false,
));
The HTML code looks like this (simplified):
<div id="languageForm_language">
<input type="radio" value="fr_FR">
<input type="radio" value="en_US">
</div>
How could I get the second item pre-selected, according to the $currentLocale value ?
In your $langs array you can specify key value pairs like this:
array(
0 => 'value1',
1 => 'value2'
)
Now, e.g. you want to preselect value2, you can set the data attribute to the key from value2:
$builder->add('language', 'choice', array(
'choices' => $langs,
'expanded' => true,
'multiple' => false,
'required' => false,
'label' => false,
'data' => 1
));
According to this, you can set your data attribute to your $currentLocale variable to preselect it. Your code should look like this:
$currentLocale = "en_US"; // This is indeed sent to the formType
$langs = array(
'fr_FR' => 'fr',
'en_US' => 'en'
);
$builder->add('language', 'choice', array(
'choices' => $langs,
'expanded' => true,
'multiple' => false,
'required' => false,
'label' => false,
'data' => $currentLocale
));
Note: the second parameter from the add() method should be choice not language.
If the form is used with a model object, just set the language on the object itself before passing it to the form:
$object->setLanguage($currentLocale);
$form = $this->createForm('some_form_type', $object);
Otherwise, set the data option to the default language key:
$builder->add('language', 'language', array(
'choices' => $langs,
'data' => $currentLocale,
// ...
));