Making Fields Required

Post about your customizations to share with others.

Moderators: Developer, Contributor

Post Reply
Colin_turner99
Posts: 1
Joined: 17 Feb 2005, 08:32

Making Fields Required

Post by Colin_turner99 »

Hi

How can i make the Product Version Field Required when entering a Bug Report

Thanks

Colin
vboctor
Site Admin
Posts: 1293
Joined: 13 Feb 2005, 22:11
Location: Redmond, Washington
Contact:

Post by vboctor »

At the moment you can do this easily for custom fields, but not for native fields. Doing this for a custom field will show the * next to the field and will validate that it is supplied before adding the issue.

However, for native fields you can check that they are not supplied and if so you can prompt the user with an error message and stop the issue from being added. However, you can't add the * which indicates that the field is mandatory.

This can be achieved by overriding the custom_function_default_issue_create_validate() custom function. This function gets as parameters all the supplied issue information. All what you need to do is to validate the information and trigger an error as necessary. Once you trigger an error the processing will stop and the issue won't be recorded and no email notifications will be sent.

For more details about custom functions see:
http://manual.mantisbt.org/manual.custo ... ctions.php

Regards,
Victor.
JohnWashburn
Posts: 1
Joined: 03 Oct 2007, 13:03

Post by JohnWashburn »

Collin:

Here is the code I added to custom_functions_inc.php in my 1.0.8 version of Mantis . It works for both project with version defined and projects with no versions defined and works on both the simple and advanced screens.

I hope this helps. Sorry about the HTML squeezing out my formatting white spaces.


<?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 );
}
}
}
?>
dingfelder
Posts: 100
Joined: 14 Aug 2005, 22:47
Location: new zealand
Contact:

Re: Making Fields Required

Post by dingfelder »

Is there an easier way to make the product version and product build fields required?

Or is this still the best way to do it?
vboctor
Site Admin
Posts: 1293
Joined: 13 Feb 2005, 22:11
Location: Redmond, Washington
Contact:

Re: Making Fields Required

Post by vboctor »

Up to Mantis 1.1.1, there is no way to make native fields required without the use of custom functions.
Migrate your MantisBT to the MantisHub Cloud
dingfelder
Posts: 100
Joined: 14 Aug 2005, 22:47
Location: new zealand
Contact:

Re: Making Fields Required

Post by dingfelder »

do you mean prior to 1.1.1? or including 1.1.1?

I am using the latest 1.1.1 release
vboctor
Site Admin
Posts: 1293
Joined: 13 Feb 2005, 22:11
Location: Redmond, Washington
Contact:

Re: Making Fields Required

Post by vboctor »

So far we haven't implemented an easier way to control the "required" attribute of native fields. If we do, then it will not make it in the 1.1.x branch since it is a new feature.
Migrate your MantisBT to the MantisHub Cloud
msiegent
Posts: 1
Joined: 22 Jan 2009, 13:53

Re: Making Fields Required

Post by msiegent »

I am currently using mantis version 1.2.0a3

is there a easy way implemented in that version to mark native fields as required and let them show up on the website with a red *?

if so, can you point out how this can be done (as an example I would like to have assign_to as required field when reporting)

thanks
MasterOfDingsbums
Posts: 4
Joined: 22 Jul 2009, 10:39

Re: Making Fields Required

Post by MasterOfDingsbums »

<Push>

This would be interresting for me, too :)
jcrespo
Posts: 1
Joined: 04 Mar 2011, 14:22

Re: Making Fields Required

Post by jcrespo »

HI!!!!

AT LAST HERE IS THE SOLUTION =)

You need to do 2 things, one is to add * to indicate that it is a mandatory field, and the other is to validate that when a bug is created that field is being completed. :D

1) ADDING *

On the main directory open the file bug_report_page.php and bug_report_advanced_page.php
On both of these files replace the current product version block with this

Code: Select all

<!-- Product Version -->
<tr <?php echo helper_alternate_class() ?>>
	<td class="category">
		<?php echo '<span class="required">*</span>', lang_get( 'product_version' ) ?>
	</td>
	<td>
		<select <?php echo helper_get_tab_index() ?> name="product_version">
			<?php print_version_option_list( $f_product_version, $t_project_id, VERSION_RELEASED ) ?>
		</select>
	</td>
</tr>
2) Validating the Product Version as a mandatory field
Up to this you should be able to see the * in red on the left of the product version label on both forms. Now we need to add a validation and a error message to display when the user forgets to input the information.

On the Core directory open bug_api.php

Add the following condition

Code: Select all

 # If product version is not specified and not defaulted + project has categories defined, then error.
		if ( is_blank( $c_version) ) {
			error_parameters( lang_get( 'product_version' ) );
			trigger_error( ERROR_EMPTY_FIELD, ERROR );
		}

And that should be it!!!

Good Luck and hope it helps :D
Reindero
Posts: 26
Joined: 07 Jul 2008, 12:05

Re: Making Fields Required

Post by Reindero »

I tried this, but now get the error before I can fill in the version...thats not right? :) Using Mantis 1.24. Any ideas how to solve this?
epninety
Posts: 1
Joined: 12 Jun 2011, 12:51

Re: Making Fields Required

Post by epninety »

Tried to use the solution posted by jcrespo

I had to make a couple of changes, to get the behaviour I wanted...

To get correct checking of the empty field, changed to the following, at the start of the 'validate' function in bug_api.php

Code: Select all

      		if ( is_blank( $this->version) ) {
         		error_parameters( lang_get( 'product_version' ) );
         		trigger_error( ERROR_EMPTY_FIELD, ERROR );
      			}
And to show all product versions, not just released ones, change the entry in bug_report_api.php

Code: Select all

	<!-- Product Version -->
	<tr <?php echo helper_alternate_class() ?>>
   		<td class="category">
      			<?php echo '<span class="required">*</span>', lang_get( 'product_version' ) ?>
   		</td>
   		<td>
      			<select <?php echo helper_get_tab_index() ?> name="product_version">
         			<?php print_version_option_list( $f_product_version, $t_project_id, $t_product_version_released_mask ) ?>
      			</select>
   		</td>
	</tr>
(all in MantisBT 1.2.5)

Hope this is useful to someone else.
andrea.mills
Posts: 35
Joined: 22 Jul 2011, 12:38

Re: Making Fields Required

Post by andrea.mills »

is there a way to validate it using custom_functions_inc.php? I'd rather not hack the core mantis files if i don't have to. and the response from earlier makes it seem like custom functions can handle the validation task, but i'm not sure that the code pasted above is still valid for mantis 1.2.6.
atrol
Site Admin
Posts: 8374
Joined: 26 Mar 2008, 21:37
Location: Germany

Re: Making Fields Required

Post by atrol »

andrea.mills wrote:is there a way to validate it using custom_functions_inc.php?
This is what vboctor described at the top of this post.
The only thing you will not get without tweaking the code is the "*" to indicate that the field is mandatory.
Please use Search before posting and read the Manual
Reinder
Posts: 119
Joined: 26 Apr 2005, 11:08

Re: Making Fields Required

Post by Reinder »

Hi,

I now always get the error, even when I do not have a product version number at all. I thought it should only give the warning when the product version was visable? Its not visable, but still generates the message.

Code used:
The changes are made in Mantis 1.2.2, but work as well in Mantis 1.2.7 (tested).

core/bug_api.php

Code: Select all

function validate( $p_update_extended =  true) {
if ( is_blank( $this->version) ) {
               error_parameters( lang_get( 'product_version' ) );
               trigger_error( ERROR_EMPTY_FIELD, ERROR );
               }
		# Summary cannot be blank
		if( is_blank( $this->summary ) ) {
			error_parameters( lang_get( 'summary' ) );
			trigger_error( ERROR_EMPTY_FIELD, ERROR );
		}
bug_report_api.php

Code: Select all

 <!-- Product Version -->
   <tr <?php echo helper_alternate_class() ?>>
         <td class="category">
               <?php echo '<span class="required">*</span>', lang_get( 'product_version' ) ?>
         </td>
         <td>
               <select <?php echo helper_get_tab_index() ?> name="product_version">
                  <?php print_version_option_list( $f_product_version, $t_project_id, $t_product_version_released_mask ) ?>
               </select>
         </td>
   </tr>
Post Reply