date picker for custom date field

Get help from other users here.

Moderators: Developer, Contributor

poooool
Posts: 3
Joined: 20 Feb 2010, 22:47

date picker for custom date field

Post by poooool »

Is it possible to use date picker (jscalendar) for custom field of date type?
Kirill
Posts: 638
Joined: 25 Nov 2007, 08:05
Location: Kaliningrad, RF
Contact:

Re: date picker for custom date field

Post by Kirill »

You can write plugin for this in MantisBT 1.2.x version
atrol
Site Admin
Posts: 8366
Joined: 26 Mar 2008, 21:37
Location: Germany

Re: date picker for custom date field

Post by atrol »

The current implementation is quite weak, so I would prefer to have this in MantisBT core and not as an additional plugin. (Of course beeing able to have plugins for any kind of own dialogs is certainly a good idea)
This feature request is already know and can be followed at:
http://www.mantisbt.org/bugs/view.php?id=8957
Monitoring the issue might push a little bit developers to have a look at it.
Or even better @poooool if you could provide a patch for it.
Please use Search before posting and read the Manual
poooool
Posts: 3
Joined: 20 Feb 2010, 22:47

Re: date picker for custom date field

Post by poooool »

I am not so good developer to create plugin nor patch. So I will wait until it is in core.
Thanks for replays.
philou2024
Posts: 12
Joined: 02 Nov 2010, 13:12
Location: France

Re: date picker for custom date field

Post by philou2024 »

I wrote it for a company. So I can provide a patch (next week-end).


changes in Mantis core
I reuse this variable in config_inc.php

$g_use_date_picker_javascript = ON;

core/date_api.php
in function print_date_selection_set
line 211

On line 2, I think there is better solution than && "/return_dynamic_filters.php" != $_SERVER["SCRIPT_NAME"]

if (ON == config_get( 'use_date_picker_javascript' )
&& "/return_dynamic_filters.php" != $_SERVER["SCRIPT_NAME"]
) {
$p_date = is_numeric( $p_date ) ? $p_date : time();
$t_date = preg_split( '/-/', date( 'Y-m-d', $p_date ), -1, PREG_SPLIT_NO_EMPTY );
$t_date_to_display = $t_date ? $t_date[0] . "-". $t_date[1] . "-". $t_date[2] : '';
print "<input ".helper_get_tab_index()." type=\"text\" size=\"14\" id=\"$p_name\" name=\"$p_name\" size=\"20\" maxlength=\"12\" value=\"".$t_date_to_display."\" />";
date_print_calendar("trigger".$p_name);
date_finish_calendar( $p_name, "trigger".$p_name);
} else {
//current code
}

core/gpc_api.php, deux change to do
function gpc_isset_custom_field
line 174
if (ON == config_get( 'use_date_picker_javascript' )) {
return gpc_isset( $t_field_name ) ;
} else {
//current code
}
function gpc_get_custom_field
line 220
if (ON == config_get( 'use_date_picker_javascript' )) {
return strtotime( gpc_get_string( $p_var_name, time() ));
} else {
//current code there
}

It works very fine on the Mantis I set up.
philou2024
Posts: 12
Joined: 02 Nov 2010, 13:12
Location: France

Re: date picker for custom date field

Post by philou2024 »

I have just added this in core/date_api.php

If Mantis Team is interested by this change, I can send it in a patch.

line 306
function date_finish_calendar( $p_field_name, $p_button_name ) {
if(( ON == config_get( 'dhtml_filters' ) ) && ( ON == config_get( 'use_javascript' ) ) ) {
$t_format = config_get( 'calendar_js_date_format' );
$t_date_picker_configure = config_get( 'date_picker_configure' );
echo "<script type=\"text/javascript\">\n";
echo "Calendar.setup (\n";
echo "{\n";
echo "inputField : \"" . $p_field_name . "\",\n";
echo "ifFormat : \"" . $t_format . "\", \n";

foreach ($t_date_picker_configure as $t_key => $t_value ) {
$quote = ($t_value == 'true' || $t_value == 'false' || is_numeric($t_value)) ? "" : '"';
echo "$t_key : $quote$t_value$quote,\n";
}

echo "button : \"" . $p_button_name . "\"\n";
echo "}\n";
echo ");\n";
echo "</script>\n";
}
}


You need to add following variable in config_inc.php
$g_date_picker_configure = array(
'timeFormat' => 24,
'firstDay' => 1,
'cache' => 'true',
'showsTime' => 'true',
);
you can any variable authorized in calendar, except : inputfield, ifformat and button

* inputField | the ID of an input field to store the date
* displayArea | the ID of a DIV or other element to show the date
* button | ID of a button or other element that will trigger the calendar
* eventName | event that will trigger the calendar, without the "on" prefix (default: "click")
* ifFormat | date format that will be stored in the input field
* daFormat | the date format that will be used to display the date in displayArea
* singleClick | (true/false) wether the calendar is in single click mode or not (default: true)
* firstDay | numeric: 0 to 6. "0" means display Sunday first, "1" means display Monday first, etc.
* align | alignment (default: "Br"); if you don't know what's this see the calendar documentation
* range | array with 2 elements. Default: [1900, 2999] -- the range of years available
* weekNumbers | (true/false) if it's true (default) the calendar will display week numbers
* flat | null or element ID; if not null the calendar will be a flat calendar having the parent with the given ID
* flatCallback | function that receives a JS Date object and returns an URL to point the browser to (for flat calendar)
* disableFunc | function that receives a JS Date object and should return true if that date has to be disabled in the calendar
* onSelect | function that gets called when a date is selected. You don't _have_ to supply this (the default is generally okay)
* onClose | function that gets called when the calendar is closed. [default]
* onUpdate | function that gets called after the date is updated in the input field. Receives a reference to the calendar.
* date | the date that the calendar will be initially displayed to
* showsTime | default: false; if true the calendar will include a time selector
* timeFormat | the time format; can be "12" or "24", default is "12"
* electric | if true (default) then given fields/date areas are updated for each move; otherwise they're updated only on close
* step | configures the step of the years in drop-down boxes; default: 2
* position | configures the calendar absolute position; default: null
* cache | if "true" (but default: "false") it will reuse the same calendar object, where possible
* showOthers | if "true" (but default: "false") it will show days from other months too

Verified on my Mantis installation.
atrol
Site Admin
Posts: 8366
Joined: 26 Mar 2008, 21:37
Location: Germany

Re: date picker for custom date field

Post by atrol »

philou2024 wrote: If Mantis Team is interested by this change, I can send it in a patch.
See http://docs.mantisbt.org/master/en/deve ... RIB.SUBMIT
You could add the patch as attachment at
http://www.mantisbt.org/bugs/view.php?id=8957
Please use Search before posting and read the Manual
philou2024
Posts: 12
Joined: 02 Nov 2010, 13:12
Location: France

Re: date picker for custom date field

Post by philou2024 »

Done, patch is available there: http://www.mantisbt.org/bugs/view.php?id=8957
atrol
Site Admin
Posts: 8366
Joined: 26 Mar 2008, 21:37
Location: Germany

Re: date picker for custom date field

Post by atrol »

philou2024, thanks for the patch.
I am wondering that your patch is quite big.
There are a lot of changes on file config_defaults_inc.php which are not related to date field
Please use Search before posting and read the Manual
philou2024
Posts: 12
Joined: 02 Nov 2010, 13:12
Location: France

Re: date picker for custom date field

Post by philou2024 »

There is only 2 changes in config file:
Parameter to use calendar
array to configure calendar

And there is changes in other files.

I'll check files tomorrow or saturday
philou2024
Posts: 12
Joined: 02 Nov 2010, 13:12
Location: France

Re: date picker for custom date field

Post by philou2024 »

I know why, I correct patch asap
M.C.S.
Posts: 1
Joined: 23 Aug 2010, 12:29

Re: date picker for custom date field

Post by M.C.S. »

philou2024 wrote:I know why, I correct patch asap
Any news? I fear that this feature won't be implemented as long as the unnecessary changes are part of the patch :roll:
cas
Posts: 1586
Joined: 11 Mar 2006, 16:08
Contact:

Re: date picker for custom date field

Post by cas »

Here are the actions to make this work under 1.2.10.
Just reviewed the work of Philou and took out what was not needed.
No, i did not create a patch but these instructions are pretty clear and can be moved into core very easily (which should have been done a long time ago) :mrgreen:
Attachments
Custom_date_field_date_picker.zip
(1.51 KiB) Downloaded 1028 times
mahendar_megha
Posts: 1
Joined: 29 Dec 2012, 09:36

Re: date picker for custom date field

Post by mahendar_megha »

I am using custom field of type date with date picker and i want to know how to set default value to "no due date" instead of "01-01-1970", either to set empty.
BStaack
Posts: 2
Joined: 29 Jun 2016, 05:15

Re: date picker for custom date field

Post by BStaack »

Hi everybody.

I´m also using costum fields with the date picker.
Unfortunately my date is also automatically set to 01-01-1970 when it´s not filled.
It should rather be empty.
What do I have to change to disable the default date?

Thanks in advance
Post Reply