How to format a numeric custom field?

Get help from other users here.

Moderators: Developer, Contributor

Post Reply
pollevr
Posts: 28
Joined: 25 Jun 2020, 15:12

How to format a numeric custom field?

Post by pollevr »

Hi all,
I created a numeric float custom field like this:
custom_field_config.png
custom_field_config.png (19.19 KiB) Viewed 1155 times
My custom field was displayed like this:
custom_field_orig.png
custom_field_orig.png (2.68 KiB) Viewed 1155 times
but I would print this custom filed on a custom format like this:
custom_field_formatted.png
custom_field_formatted.png (3.07 KiB) Viewed 1155 times
How can I do it?

Thanks.
pollevr
Posts: 28
Joined: 25 Jun 2020, 15:12

Re: How to format a numeric custom field?

Post by pollevr »

I found a solution, in bug_view_inv.php:

Code: Select all

# Custom Fields
if( isset( $t_issue['custom_fields'] ) ) {
	foreach( $t_issue['custom_fields'] as $t_custom_field ) {
		$t_def = custom_field_get_definition( $t_custom_field['field']['id'] );

		echo '<tr>';
		echo '<th class="bug-custom-field category" colspan="2">', string_display_line( lang_get_defaulted( $t_def['name'] ) ), '</th>';
		echo '<td class="bug-custom-field" colspan="4">';
		//print_custom_field_value( $t_def, $t_custom_field['field']['id'], $f_issue_id );
    if($t_def['type']==2 && is_numeric ($t_custom_field['value'])){
      echo number_format($t_custom_field['value'], 2, ",", ".");
    }else{
      print_custom_field_value( $t_def, $t_custom_field['field']['id'], $f_issue_id );
    }
		echo '</td></tr>';
	}
Let me know if there is a better solution.

Thank you.
Post Reply