I'd like to ask you for support. The yii2 Kartik datetimepicker extension is giving strange and random start date. After clicking the calendar the start date might be year 4678 or year 3599. Imagine scrolling this back to 2017 :) Have you ever faced similar issues. I have checked the forum and I was not able to find the answer.
Here is my code.
<?php
// Usage with model (with no default initial value)
echo $form->field($date, 'start_time')->widget(
DateTimePicker::className(),
[
'size'=>'md',
'type' => DateTimePicker::TYPE_COMPONENT_APPEND,
'convertFormat' => true,
'pluginOptions' => [
'todayHighlight' => true,
'todayBtn' => true,
'format' => 'dd-M-yyyy H:i',
'autoclose' => true,
'startDate'=> date('d-m-Y H:i', strtotime(time())),
],
])->label('Start Date');
?>
Here is the screen shot of the datetimepicker: https://ibb.co/fu5WFw
The second parameter of date() is a timestamp, so remove strtotime():
'startDate'=> date('d-m-Y H:i',time()),
Related
I'm trying to have a time input in TYPO3 9 LTS working together with MySQL 5.7.24.
In the ext_tables.sql the field gets defined like this:
some_field time default NULL
In the TCA the field gets defined like this:
'some_field' => [
'exclude' => 1,
'label' => 'Some field',
'config' => [
'type' => 'input',
'dbType' => 'time',
'eval' => 'time',
],
],
When saving the record in the backend without a time input (which should be possible) I'm getting the error:
These fields of record 1 in table "some_table" have not been saved correctly: some_field! The values might have changed due to type casting of the database.
When looking at the database record the some_field field gets the value 00:00:00 (although the db default is NULL).
When selecting a time the record can be saved and opened without error.
Is this a bug in TYPO3 or how could I fix this behavior?
The bug can be solved by having the following eval:
'eval' => 'time,null',
That means you have given the wrong type for the value on your ext_tables.sql. Additionally, TYPO3 v9 has renderTypes.
Try something like that:
ext_tables.sql
begin int(11) DEFAULT '0' NOT NULL
TCA
'begin' => [
'exclude' => true,
'label' => 'LLL:EXT:your_ext/Resources/Private/Language/locallang_db.xlf:tx_yourext_domain_model_modelname.begin',
'config' => [
'type' => 'input',
'renderType' => 'inputDateTime',
'size' => 10,
'eval' => 'datetime',
'default' => time()
],
],
Additional information!
If you want to display the time in FrontEnd you could use something like that
<f:format.date>{dateObject.begin}</f:format.date>
If you want to modify how it looks, you can use the format attribute as well:
<f:format.date format="%d. %B %Y">{dateObject.begin}</f:format.date>
More about that here: TYPO3 Date format
I'm using Yii2 and I would like to have the following things:
A dropdown with "ranges" as items (week, full week, week-end, etc.) (done)
A RangePicker that based on the chosen range will:
allow only some days as the startDate (ex: week = mondays; week-end = saturdays)
will automatically select the end date based on the start date (ex: week: monday to friday; full week: monday to sunday; week-end: saturday to sunday, etc.)
For the dropdown, it's fine. But for the DateRangePicker, I started using Krajee DateRangePicker and
I do not find a callback for "onStartDateSelected" (I only saw a callback that is called when the range is selected, but not for individual start date or end date)
I do not see a "setStopDate" function
I do not see how to dynamically change the available days of weeks
I see that we can have a set of predefined periods like "last 7 days", "this month", etc. But this is not what I want. I want the user be able to select the start date but automatically calculate the end date based on what the user has set.
(I'm new in web dev, so please if you find anything that I could improve in my question, don't be afraid to share it)
You can use the following to accomplish the task:
Use the following library:
use kartik\date\DatePicker;
Use the following code in view:
<?php
$layout3 = '<span class="input-group-addon">From Date</span>
{input1}
<span class="input-group-addon">To Date</span>
{input2}
<span class="input-group-addon kv-date-remove">
<i class="glyphicon glyphicon-remove"></i>
</span>';
$previousDay = strtotime('-7 day', strtotime(date('d-M-Y'))); //Set as per your requirement[![enter image description here][1]][1]
echo DatePicker::widget([
'type' => DatePicker::TYPE_RANGE,
'name' => 'startDate',
'value' => date('d-M-Y', $previousDay),
'name2' => 'endDate',
'value2' => date('d-M-Y'),
'separator' => '<i class="glyphicon glyphicon-resize-horizontal"></i>',
'layout' => $layout3,
'pluginOptions' => [
'autoclose' => true,
'format' => 'dd-M-yyyy'
]
]);
?>
Is there any way to show pageSummary of all data even if there is pagination?
[
'attribute' => 'sale_total',
'pageSummary' => true,
'hAlign' => 'right',
'format' => ['decimal',2],
],
This shows only sum per page but I wanted it of all the data, not a particular page.
By Clicking the All(Show all data) link(On the right side toolbar options), the sum of all the records total will be displayed.
Try:
'summary' => {totalCount},
I'm not sure if this is what you are looking for.
I am using 2amigos/yii2-date-picker-widget.After selecting the date, user can edit the year which can be invalid like 10/30/0233. (m/d/Y)
I want to restrict user to enter invalid year, or to allow the date between specific year range only. without making the datefield readonly. How can I achieve this.
echo $form->field($model, 'date')->widget(DatePicker::className(), [
'addon' => '<i class="fa fa-calendar" aria-hidden="true"></i>',
'class' => 'form-control',
'clientOptions' => [
'autoclose' => true,
'format' => Yii::$app->params['dateFormat'],
],
]);
I have solved it using custom validator as follows
add rule for date as follows
['my_date', 'validYear'], // custom validator to check year range
Then define custom rule as follows
public function validYear($attribute, $params) {
$date = DateTime::createFromFormat("m/d/Y", $this->my_date);
$year = $date->format("Y");
$year_range = range(date('Y'), date('Y')+20, 1);
if(!empty($year) && !in_array($year, $year_range)){
$this->addError($attribute,"Please select valid date");
}
}
Though it works perfectly for me, If anyone has more appropriate solution, please suggest.
I am working on a module that requires some html to be entered to be later called upon and become part of a customer facing widget output.
I've created an administrative backend and that is all working properly, however when I enter html into the field that should be storing the data i receive an error.
I dont need the wysiwyg but I would like to be able to enter html into this value.
At this point I've not done anything special when adding the field to the fieldset. What am I missing?
$contentField = $fieldset->addField('inner_html', 'editor', array(
'name' => 'inner_html',
'style' => 'height:36em;width:36em',
'required' => false,
));
Try
$fieldset->addField('inner_html', 'editor', array(
'name' => 'inner_html',
'label' => Mage::helper('tag')->__('Description'),
'title' => Mage::helper('tag')->__('Description'),
'style' => 'width:700px; height:350px;',
'config' => Mage::getSingleton('cms/wysiwyg_config')->getConfig(array('add_variables' => false, 'add_widgets' => false,'files_browser_window_url'=>$this->getBaseUrl().'admin/cms_wysiwyg_images/index/')),
'wysiwyg' => true,
'required' => false,
));