Default fields mandatory

Get help from other users here.

Moderators: Developer, Contributor

Post Reply
Reindero
Posts: 26
Joined: 07 Jul 2008, 12:05

Default fields mandatory

Post by Reindero »

Trying to make some default fields mandatory (like product version and comments on status change).

However, when using hte code below, I get an error when the product version is filled in or not (so always actually).

Code: Select all

<?php 
# --------------------
# Hook to validate field settings before creating an issue
# Verify that the proper fields are set before proceeding to create an issue
# In case of errors, this function should call trigger_error()
# p_new_issue_data is an object (BugData) with the appropriate fields updated
# --------------------
# This code was ripped off and mutated from the following files
# custom_function_api.php,v 1.25 2005/07/23 12:01:48
# bug_view_page.php,v 1.77.6.1.4.1 2007/03/06 07:00:33 and
# bug_api.php,v 1.95.8.1.6.1 2006/04/18 00:53:04 thraxisp 
#
# The test for IF there is a product version to select was mutated from bug_view_page.php. 
# Should this be a core mantis function found in bug_api.php and is named: is_product_version_visible()?
# bug_create() of bug_api.php for the test for blank value and throwing the correct error message
# --------------------
function custom_function_override_issue_create_validate( $p_new_issue_data ) {
# the purpose of this override is to add to the current validation functionality
# So, call the current validator when creating a new mantis report
# I don't know if this chaining of behavior is MANTIS typical
custom_function_default_issue_create_validate( $p_new_issue_data );

# Decide if product_version is available on the report entry screen being validated for the user
$c_project_id = helper_get_current_project();
$show_product_version_config = config_get( 'show_product_version' );
$show_product_version_counts = count( version_get_all_rows( $c_project_id) );
$is_product_version_visible = ( ON == $show_product_version_config ) 
|| ( ( AUTO == $show_product_version_config )
&& ( 0 < $show_product_version_counts ) );
if ( $is_product_version_visible ) {

# if the field, product version, is visible to the user, 
# then trigger an error if the product version is blank
$c_version = db_prepare_string( $p_bug_data->version );
if ( is_blank( $c_version) ) {
error_parameters( lang_get( 'product_version' ) );
trigger_error( ERROR_EMPTY_FIELD, ERROR );
}
}
}
?>
I tried to understand the custom functions (http://docs.mantisbt.org/master/en/admi ... USTOMFUNCS) but have no clue how to adapt this to the fields I want to be mandatory....
rnm
Posts: 4
Joined: 18 Mar 2023, 07:52

Re: Default fields mandatory

Post by rnm »

I do something like this today by mandatory the product_version and target_version. I just do this.

Code: Select all

// File: \core\custom_function_api.php
function custom_function_default_issue_create_validate( BugData $p_new_issue_data ) {
	// print "<pre>";	print_r($p_new_issue_data);	print "</pre>";
	$f_target_version		= $p_new_issue_data->target_version;
	$f_product_version		= $p_new_issue_data->version;

	if(is_blank( $f_product_version) ) {
		error_parameters( 'product_version' );
		trigger_error( ERROR_EMPTY_FIELD, ERROR );
	}

	if(is_blank( $f_target_version) ) {
		error_parameters( 'target_version' );
		trigger_error( ERROR_EMPTY_FIELD, ERROR );
	}
}
For UI. i do adjustment directly to file
```
diff --git a/bug_report_page.php b/bug_report_page.php
index 6c05baf..a61e51c 100644
--- a/bug_report_page.php
+++ b/bug_report_page.php
@@ -455,10 +455,10 @@ if( $t_show_attachments ) {
?>
<tr>
<th class="category">
- <label for="product_version"><?php echo lang_get( 'product_version' ) ?></label>
+ <span class="required">*</span><label for="product_version"><?php echo lang_get( 'product_version' ) ?></label>
</th>
<td>
- <select <?php echo helper_get_tab_index() ?> id="product_version" name="product_version" class="input-sm">
+ <select <?php echo helper_get_tab_index() ?> id="product_version" name="product_version" class="input-sm" required>
<?php print_version_option_list( $f_product_version, $t_project_id, $t_product_version_released_mask ) ?>
</select>
</td>
@@ -548,10 +548,10 @@ if( $t_show_attachments ) {
if( $t_show_target_version ) { ?>
<tr>
<th class="category">
- <label for="target_version"><?php echo lang_get( 'target_version' ) ?></label>
+ <span class="required">*</span><label for="target_version"><?php echo lang_get( 'target_version' ) ?></label>
</th>
<td>
- <select <?php echo helper_get_tab_index() ?> id="target_version" name="target_version" class="input-sm">
+ <select <?php echo helper_get_tab_index() ?> id="target_version" name="target_version" class="input-sm" required>
<?php print_version_option_list( '', null, VERSION_FUTURE ) ?>
</select>
</td>
```

For more details, check https://github.com/RobbiNespu/mantisbt/ ... f93ab9fb9f
cas
Posts: 1688
Joined: 11 Mar 2006, 16:08
Contact:

Re: Default fields mandatory

Post by cas »

there is a plugin to take care of this, check out here:
https://github.com/mantisbt-plugins/FieldMan
Post Reply