[solved] customfield Datepicker 1.2.19 default values

Get help from other users here.

Moderators: Developer, Contributor

Post Reply
joey2.0
Posts: 10
Joined: 06 Jan 2016, 13:05

[solved] customfield Datepicker 1.2.19 default values

Post by joey2.0 »

Hi guys,

i am testing the datepicker -> https://github.com/mantisbt/mantisbt/pull/65/files, i also added the code from here: http://www.mantisbt.org/bugs/view.php?id=8957
to have no default value.
I need some clarification, i have some customfields which are not shown on ticket creation, ~ devs should fill it out later.
But after ticket creation they are set to 1970/01/01, is this normal behaivour, or did i mess something up in the code?
If i disable the datepicker everything works fine. Someone is running a working datepicker under 1.2.19?


Update: Seems like the missing fields got a 0 at creation which would be displayed as the default date.
Following Change solves it: add the 4 commented lines in custom_field_api.php(type = 8 should always be the type for date field i guess) :

Code: Select all

function string_custom_field_value( $p_def, $p_field_id, $p_bug_id ) {
	$t_custom_field_value = custom_field_get_value( $p_field_id, $p_bug_id );
	if( $t_custom_field_value === null ) {
		return '';
	}
#only the following 4 lines are new:
	if ( $t_custom_field_value == '0' && $p_def['type'] == '8')
	{
		return '';
	}
	
	global $g_custom_field_type_definition;
	if( isset( $g_custom_field_type_definition[$p_def['type']]['#function_string_value'] ) ) {
		return call_user_func( $g_custom_field_type_definition[$p_def['type']]['#function_string_value'], $t_custom_field_value );
	}
	return string_display_links( $t_custom_field_value );
}
Thanks and Regards
Joey
BStaack
Posts: 2
Joined: 29 Jun 2016, 05:15

Re: [solved] customfield Datepicker 1.2.19 default values

Post by BStaack »

Hi and thanks for this tip.
Unfortunately your trick is just working once you create your ticket.
But if you´re going to edit it afterwards, the 1970-01-01 will be filled in the date field.
It seems that it is still going to load the default when going into edit mode again.
Did you also found a solution for this?

Thanks in advance
joey2.0
Posts: 10
Joined: 06 Jan 2016, 13:05

Re: [solved] customfield Datepicker 1.2.19 default values

Post by joey2.0 »

it is working for me, it seems i forgot something, check your date_api.php in mantis/core:

mine looks like this, i think the 4 lines starting with : if($p_date==0)... were added by me later and the others are out of a comment from the mentioned ticket:

Code: Select all

function print_date_selection_set( $p_name, $p_format, $p_date =0, $p_default_disable = false, $p_allow_blank = false, $p_year_start = 0, $p_year_end = 0 ) {
                if (ON == config_get( 'use_date_picker_javascript' )  
                        && "/return_dynamic_filters.php" != $_SERVER["SCRIPT_NAME"]  
                ) {
 if ($p_date == 0)
                {
                        $t_date_to_display =  ''';
                }
                else{
                        if(is_numeric( $p_date )) {
                        $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] : '';
                        } else {
                        $t_date_to_display = '';
                        }
                }
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, false );  

        } else {
.
.
.
hope it will work for you with this, feedback appreciated.
zemaria523
Posts: 2
Joined: 15 Mar 2021, 20:36

Re: [solved] customfield Datepicker 1.2.19 default values

Post by zemaria523 »

Hi, How can it be used in filters? Were you able to code it ?
Post Reply