How add time to datepicker in backend magento - php

I'am using magento 1.7.2 and I want to add date attribute with time which saves date as well as time in database for that product.
i had tried this code to add new attribute using mysql-setup file in my module.
$setup->addAttribute('catalog_product', 'new_date', array(
'group' => 'General',
'input' => 'date',
'type' => 'datetime',
'label' => 'New Date',
'backend' => 'eav/entity_attribute_backend_datetime',
'visible' => 1,
'required' => 0,
'user_defined' => 1,
'searchable' => 1,
'filterable' => 1,
'comparable' => 1,
'visible_on_front' => 1,
'visible_in_advanced_search' => 0,
'is_html_allowed_on_front' => 1,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));
but this gives me only date to select not time.
Please help me.
Thanks.

Try this for backend (any admin panel form):
$fieldset->addField('your_column_name', 'date',array(
'name' => 'image_link', /* should match with your table column name where the data should be inserted */
'time' => true,
'class' => 'required-entry',
'required' => true,
'format' => $this->escDates(),
'label' => Mage::helper('featuredpopup')->__('From:'),
'image' => $this->getSkinUrl('images/grid-cal.gif')
));
in format u can write directly 'yyyy-MM-dd HH:mm:ss' or one more method like
private function escDates() {
return 'yyyy-MM-dd HH:mm:ss';
}
Hopes this gives u an idea.

Try these (works on Magento 1.8):
$this->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'test_date_time', array(
'input' => 'datetime',
'type' => 'datetime',
'time' => true,
'label' => 'Date&Time',
'visible' => true,
'required' => false,
'user_defined' => true,
'visible_on_front' => true,
'backend' => 'eav/entity_attribute_backend_time_created',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL
));

Hello check app/code/local/Magik/Popup/Block/Adminhtml/Popup/Edit/Tab/Form.php
Add below code
$dateFormatIso=Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
$fieldset->addField("text_name", "date", array(
"name" => "text_name",
"label" => Mage::helper("modelname")->__("Start Date"),
"title" => Mage::helper("modelname")->__("Start Date"),
"image" => $this->getSkinUrl('images/grid-cal.gif'),
"input_format" => Varien_Date::DATE_INTERNAL_FORMAT,
"format" => $dateFormatIso,
"time" => false,
"value" => "textstart",
));

when creating a custom attribute you just need to add
'input'=> 'datetime' instead of 'input'=> 'date'

Related

unable to change date format for user view in cjuidatepicker in yii1

$this->widget('zii.widgets.jui.CJuiDatePicker',array(
'name'=>'date_from',
'id' => 'date_from',
//'value'=> date('d/m/Y',strtotime($date_from)),
'options'=>array(
'dateFormat' =>'dd/mm/yy',
'altFormat' =>'dd/mm/yy',
'changeMonth' => true,
'changeYear' => true,
'showAnim'=>'slide',
'showButtonPanel'=>true,
),
'language' => 'en-GB',
'htmlOptions'=>array(
'class'=>'form-control'
),
));
This is the code for the date picker so I want the user to view the date in the following format: dd/mm/yy. I want it seperated with slashes.
This works in Yii 1.20 with JQuery 1.11.2 I added additional parameters just as reference.
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'model' => $model,
'attribute' => 'date_from',
'language' => 'en',
'options' => array(
'showAnim' => 'fold',
'dateFormat' => 'yy/mm/dd',
'showOtherMonths' => true,
'selectOtherMonths' => true,
'changeYear' => true,
'changeMonth' => true,
'yearRange' => "2000:2020",
'showWeek' => false,
'firstDay' => 1
),
'htmlOptions' => array(
'size' => '10',
'maxlength' => '10',
'class' => 'form-control'
)
));

Yii CJuiDatePicker is not working when page loaded with ajax but works with direct url access

It is little confusing the working of CJuiDatePicker widget. when i accessing page with direct URL it working fine and calender displayed as required but the problem is that when i load the page into a dynamic portion with ajax call,Only text-fields are appearing but calender is not displaying after clicking on it.
$this->renderPartial('index', array('policyModel' => $policyModel, 'roomModel' => $roomModel, 'formModel' => $formModel,'response' => $response),false,true);
Widget Code
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'name' => 'start_date',
'options' => array(
'dateFormat' => 'yy-mm-dd',
'showAnim' => 'fadeIn',
'changeMonth' => true,
'changeYear' => true,
'yearRange' => '2000:2099',
'minDate' => '+1d',
'maxDate' => '10Y',
),
'htmlOptions' => array(
'readonly' => 'readonly',
'size' => 7,
),
));
Can any one please help me ,I am posting the question after so many hours of search.
You have to set a unique ID for the datepicker. I do so with the php-function uniqid()
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'id' => 'start_date'.uniqid(),
'name' => 'start_date',
'options' => array(
'dateFormat' => 'yy-mm-dd',
'showAnim' => 'fadeIn',
'changeMonth' => true,
'changeYear' => true,
'yearRange' => '2000:2099',
'minDate' => '+1d',
'maxDate' => '10Y',
),
'htmlOptions' => array(
'readonly' => 'readonly',
'size' => 7,
),
));
Good luck!
You need re-init datepicker after ajax update.After Ajax done, you'll need to add the following line:
$('#start_date').datepicker(); //with your options

Saving custom attribute value for category in magento

I have been trying to create an attribute for the categories in magento at the backend through programmatically. So, I followed steps in http://www.hesselbom.net/magento-custom-attributes-with-selectbox and it works perfectly and even I can able to save the selected values. Whereas, if I try creating a text box attribute, the values is not getting saved. Can anyone guide me how to do this?
Following is my code.
$installer->addAttribute('catalog_category', 'custom_textfield', array(
'type' => 'varchar',
'label' => 'Custom field',
'input' => 'text',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
'visible' => TRUE,
'required' => FALSE,
'default' => ''
));
$attributeId = $installer->getAttributeId($entityTypeId, 'custom_textfield');
I have also updated the version in the config file accordingly.
Please try with it work for me
$installer->addAttribute('catalog_category', 'custom_textfield', array(
'group' => 'General',
'input' => 'text',
'type' => 'varchar',
'label' => 'Custom field ',
'backend' => '',
'visible' => 1,
'required' => 0,
'user_defined' => 1,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));
$this->addAttribute('catalog_category', 'custom_textfield', array(
'group' => 'General',
'type' => 'varchar',//can be int, varchar, decimal, text, datetime
'backend' => '',
'frontend_input' => '',
'frontend' => '',
'label' => 'Custom Field',
'input' => 'image', //text, textarea, select, file, image, multilselect
'class' => '',
'source' => '[source model for attribute here]',//this is necessary for select and multilelect, for the rest leave it blank
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,//scope can be SCOPE_STORE or SCOPE_GLOBAL or SCOPE_WEBSITE
'visible' => true,
'frontend_class' => '',
'required' => false,//or true
'user_defined' => true,
'default' => '',
'position' => 100,//any number will do
));
This should do the trick. :)
After a long search, I found it. Below is the way to create and save attribute value at the admin panel.
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->addAttribute('catalog_category', 'length_waterline_custom', array(
'group' => 'General',
'input' => 'text',
'type' => 'varchar',
'label' => 'Length of Waterline',
'backend' => '',
'visible' => 1,
'required' => false,
'user_defined' => 1,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));
$eavConfig = Mage::getSingleton('eav/config');

CJuiDatepicker hide on select

I'm trying to force the CJuiDatepicker to hide after I select the date. Nothing works. How could I achieve it?
Here's my actual code:
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'model' => $model,
'attribute' => 'confirmStart',
'options' => array(
'format' => 'yyyy-mm-dd',
'showButtonPanel' => false,
'onSelect' => 'js:function() {
$("#Projects_confirmStart").datepicker("hide");
}
',
),
));
It is working fine in my test Yii app. Check your program with mozilla firebug. You may get error in console when you select the date. May be your datepicker functionality is effecting by some other plugins/scripts.
This work for me.
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'model' => $model,
'attribute' => 'fechaAdq',
'language' => 'es',
'i18nScriptFile' => 'jquery-ui-i18n.min.js',
'htmlOptions' => array(
'id' => 'FMAIDetalleAdq_fechaAdq',
'size' => '10', * *'onChange' => 'jQuery("#FMAIDetalleAdq_fechaAdq").datepicker("hide")' * *
) ,
'defaultOptions' => array(
'showOn' => 'focus',
'showOtherMonths' => true,
'selectOtherMonths' => true,
'changeMonth' => true,
'changeYear' => true,
'showButtonPanel' => true,
) ,
'options' => array(
'showAnim' => 'fold',
'format' => 'dd-mm-yyyy',
'language' => 'es',
) ,
) , true);

yii : How to setup different setting for different date picker at a single form?

Problem : the application has 2 or more date picker. They are defined by id and name. And their date setting should not be same.
e.g exchange rate date should be today date only. And ETA complete date should not be today date.
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'name'=>'Request[exchange_date]',
'model'=>$model,
'value' => $model->exchange_date,
'i18nScriptFile' => 'jquery.ui.datepicker-ja.js', // (#2)
'htmlOptions' => array(
'id' => 'Request_exchange_date',
'size' => '10',
),
'defaultOptions' => array( // (#3)
'showOn' => 'focus',
'dateFormat' => 'dd-M-yy',
'showOtherMonths' => true,
'selectOtherMonths' => true,
'changeMonth' => true,
'changeYear' => true,
'showButtonPanel' => true,
'yearRange'=>'0:+1',
//'minDate'=> 0,
)
));
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'name'=>'Request[eta_date]',
'model'=>$model,
'value' => $model->eta_date,
'i18nScriptFile' => 'jquery.ui.datepicker-ja.js', // (#2)
'htmlOptions' => array(
'id' => 'Request_eta_date',
'size' => '10',
),
'defaultOptions' => array( // (#3)
'showOn' => 'focus',
'dateFormat' => 'dd-M-yy',
'showOtherMonths' => true,
'selectOtherMonths' => true,
'changeMonth' => true,
'changeYear' => true,
'showButtonPanel' => true,
'yearRange'=>'0:+1',
'minDate'=> 0,
)
));
Q : How can I be setup different setting for different date picker at single form?
I think you should set 'options' instead of 'defaultOptions' while using CJuiDatePicker. by using 'defaultOptions' you are forcing all other instances of date picker to behave the same.

Categories