1

I am working on configuration page for the custom module, using datepicker with date module.

When i set #date_format to 'd-m-Y' its ok, i need a day-month-year format but when i submit form and trying to get variable from variable_get(), i see only year-month-day format,

GOAL: i need this variable to show up as default value or maybe placeholder in proper date format ('d-m-Y'),

minor goal: also i want this datepicker not showing up "today" but i need date position in calendar to stick on variable from variable_get(). Thanks!

function mymodule_admin($form, &$form_state) {


$form['mymodule_start_date'] = array(
    '#type' => 'date_popup',
    '#title' => t('Start date'),
    '#date_format' => 'd-m-Y',
    '#attributes' => array('placeholder' => variable_get('mymodule_start_date'),
    '#datepicker_options' => array('maxDate' => 0),
    '#date_year_range' => '-3:+0',
    '#date_label_position' => 'above',
    '#theme_wrappers' => array('date_popup'),
    '#required' => TRUE, 
);

return system_settings_form($form);

};

EDIT: my resource datepicker API

2

EDIT: fixed by setting up drupal date format and using datepicker_options:

$form['mymodule_start_date'] = array(
'#type' => 'date_popup',
'#title' => t('Start date'),
'#date_format' => 'd-m-Y',
'#datepicker_options' => array(
    'maxDate' => 0,
    'dateFormat' => date_popup_format_to_popup('d-m-Y'),
    ),
'#date_year_range' => '-3:+0',
'#date_label_position' => 'above',
'#theme_wrappers' => array('date_popup'),
'#required' => TRUE, 

);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.