View Issue Details

IDProjectCategoryView StatusLast Update
0011684mantisbtcustom fieldspublic2014-12-22 08:24
Reporterdavid_s_nl Assigned Tovboctor  
PrioritynormalSeveritymajorReproducibilityalways
Status closedResolutionfixed 
Product Versiongit trunk 
Target Version1.2.5Fixed in Version1.2.5 
Summary0011684: Incorrect error "A necessary field "MyField" was empty. Please recheck your inputs." when submitting new issue
Description

When creating a new issue i get an application error 11: "A necessary field "my custom field" was empty. Please recheck your inputs.".

This error message is not correct because "Required On Report" was not checked for the corresponding custom field.

Steps To Reproduce

I have reproduced this error on "mantisbt-1.2.0-2010-03-17-master-1.2.x-e961c55.zip", on an empty database;

  1. Logged in as Administrator
  2. Created a new project
  3. Created a new custom field
  4. Linked the custom field to the project
  5. Report a new issue -> fill in the required fields -> submit report
  6. You get the error "A necessary field "MyCustomField" was empty. Please recheck your inputs.".

See the attached screenshot for the custom field properties.

TagsNo tags attached.
Attached Files
MantisManageCustomField.png (20,470 bytes)   
MantisManageCustomField.png (20,470 bytes)   
11684.diff (2,821 bytes)   
--- C:/mantisbt-1.2.1-official/bug_report.php	Fri Apr 23 14:28:34 2010
+++ H:/mantisbt-1.2.1-custom/bug_report.php	Thu May 27 11:39:49 2010
@@ -104,18 +104,31 @@
 		$t_def = custom_field_get_definition( $t_id );
 
 		# Produce an error if the field is required but wasn't posted
-		if ( !gpc_isset_custom_field( $t_id, $t_def['type'] ) &&
-			( $t_def['require_report'] ||
-				$t_def['type'] == CUSTOM_FIELD_TYPE_ENUM ||
-				$t_def['type'] == CUSTOM_FIELD_TYPE_LIST ||
-				$t_def['type'] == CUSTOM_FIELD_TYPE_MULTILIST ||
-				$t_def['type'] == CUSTOM_FIELD_TYPE_RADIO ) ) {
+		if	(	$t_def['require_report']
+			&&	(	$t_def['type'] == CUSTOM_FIELD_TYPE_ENUM
+				||	$t_def['type'] == CUSTOM_FIELD_TYPE_LIST
+				||	$t_def['type'] == CUSTOM_FIELD_TYPE_MULTILIST
+				||	$t_def['type'] == CUSTOM_FIELD_TYPE_RADIO
+				)
+			&& !gpc_isset_custom_field( $t_id, $t_def['type'] )
+			) {
 			error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) );
 			trigger_error( ERROR_EMPTY_FIELD, ERROR );
 		}
-		if ( !custom_field_validate( $t_id, gpc_get_custom_field( "custom_field_$t_id", $t_def['type'], NULL ) ) ) {
-			error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) );
-			trigger_error( ERROR_CUSTOM_FIELD_INVALID_VALUE, ERROR );
+		if( gpc_isset_custom_field( $t_id, $t_def['type'] ) ) {
+			$t_custom_field_value = gpc_get_custom_field( "custom_field_$t_id", $t_def['type'], NULL );
+			if	(	$t_def['display_report']
+				&&	!custom_field_validate(
+							$t_id,
+							$t_custom_field_value
+						) 
+				) {
+				error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) );
+				trigger_error( ERROR_CUSTOM_FIELD_INVALID_VALUE, ERROR );
+			}
 		}
 	}
 
@@ -135,14 +148,32 @@
 
 	# Handle custom field submission
 	foreach( $t_related_custom_field_ids as $t_id ) {
+		$t_def = custom_field_get_definition( $t_id );
 		# Do not set custom field value if user has no write access.
-		if( !custom_field_has_write_access( $t_id, $t_bug_id ) ) {
+		if	(	!$t_def['display_report']
+			||	!custom_field_has_write_access( $t_id, $t_bug_id )
+			) {
+			continue;
+		}
+		
+		$t_custom_field_value = gpc_get_custom_field( "custom_field_$t_id", $t_def['type'], '');
+		if	(	empty($t_custom_field_value)
+			&&	!$t_def['require_report']
+			) {
 			continue;
 		}
 
-		$t_def = custom_field_get_definition( $t_id );
-		if( !custom_field_set_value( $t_id, $t_bug_id, gpc_get_custom_field( "custom_field_$t_id", $t_def['type'], '' ), false ) ) {
+		if( !custom_field_set_value( $t_id, $t_bug_id, $t_custom_field_value, false ) ) {
			error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) );
 			trigger_error( ERROR_CUSTOM_FIELD_INVALID_VALUE, ERROR );
 		}
11684.diff (2,821 bytes)   
11684-2.diff (2,658 bytes)   
--- C:/mantis/mantisbt-1.2.1-official/bug_report.php	Fri Apr 23 14:28:34 2010
+++ C:/mantis/mantisbt-1.2.1-patches/bug_report.php	Fri Jun 04 11:21:34 2010
@@ -104,18 +104,24 @@
 		$t_def = custom_field_get_definition( $t_id );
 
 		# Produce an error if the field is required but wasn't posted
-		if ( !gpc_isset_custom_field( $t_id, $t_def['type'] ) &&
-			( $t_def['require_report'] ||
-				$t_def['type'] == CUSTOM_FIELD_TYPE_ENUM ||
-				$t_def['type'] == CUSTOM_FIELD_TYPE_LIST ||
-				$t_def['type'] == CUSTOM_FIELD_TYPE_MULTILIST ||
-				$t_def['type'] == CUSTOM_FIELD_TYPE_RADIO ) ) {
+		if	(	$t_def['require_report']
+			&&	$t_def['type'] != CUSTOM_FIELD_TYPE_CHECKBOX
+			&&	!gpc_isset_custom_field($t_id, $t_def['type'])
+			) {
 			error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) );
 			trigger_error( ERROR_EMPTY_FIELD, ERROR );
 		}
-		if ( !custom_field_validate( $t_id, gpc_get_custom_field( "custom_field_$t_id", $t_def['type'], NULL ) ) ) {
-			error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) );
-			trigger_error( ERROR_CUSTOM_FIELD_INVALID_VALUE, ERROR );
+		if(gpc_isset_custom_field($t_id, $t_def['type'])) {
+			$t_custom_field_value = gpc_get_custom_field("custom_field_$t_id", $t_def['type'], NULL);
+			if	(	$t_def['display_report']
+				&&	!custom_field_validate(
+							$t_id,
+							$t_custom_field_value
+						) 
+				) {
+				error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) );
+				trigger_error( ERROR_CUSTOM_FIELD_INVALID_VALUE, ERROR );
+			}
 		}
 	}
 
@@ -135,13 +141,21 @@
 
 	# Handle custom field submission
 	foreach( $t_related_custom_field_ids as $t_id ) {
+		$t_def = custom_field_get_definition( $t_id );
 		# Do not set custom field value if user has no write access.
-		if( !custom_field_has_write_access( $t_id, $t_bug_id ) ) {
+		if	(	!$t_def['display_report']
+			||	!custom_field_has_write_access( $t_id, $t_bug_id )
+			) {
 			continue;
 		}
 
-		$t_def = custom_field_get_definition( $t_id );
-		if( !custom_field_set_value( $t_id, $t_bug_id, gpc_get_custom_field( "custom_field_$t_id", $t_def['type'], '' ), false ) ) {
+		$t_custom_field_value = gpc_get_custom_field( "custom_field_$t_id", $t_def['type'], '');
+		if	(	empty($t_custom_field_value)
+			&&	!$t_def['require_report']
+			) {
+			continue;
+		}
+		if(!custom_field_set_value($t_id, $t_bug_id, $t_custom_field_value, false)) {
 			error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) );
 			trigger_error( ERROR_CUSTOM_FIELD_INVALID_VALUE, ERROR );
 		}
11684-2.diff (2,658 bytes)   
11684-2-bug_update.diff (1,561 bytes)   
--- C:/mantis/mantisbt-1.2.1-official/bug_update.php	Fri Apr 23 14:28:34 2010
+++ C:/mantis/mantisbt-1.2.1-patches/bug_update.php	Wed Jun 30 09:42:05 2010
@@ -137,19 +137,19 @@
 			continue;
 		}
 
+		$t_old_custom_field_value = custom_field_get_value( $t_id, $f_bug_id );
 		# Produce an error if the field is required but wasn't posted
-		if ( !gpc_isset_custom_field( $t_id, $t_def['type'] ) &&
-			( $t_def['require_' . $t_custom_status_label] ||
-				$t_def['type'] == CUSTOM_FIELD_TYPE_ENUM ||
-				$t_def['type'] == CUSTOM_FIELD_TYPE_LIST ||
-				$t_def['type'] == CUSTOM_FIELD_TYPE_MULTILIST ||
-				$t_def['type'] == CUSTOM_FIELD_TYPE_RADIO ) ) {
-			error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) );
-			trigger_error( ERROR_EMPTY_FIELD, ERROR );
+		if	(	$t_def['require_' . $t_custom_status_label]
+			&&	$t_def['type'] != CUSTOM_FIELD_TYPE_CHECKBOX
+			&&	!gpc_isset_custom_field($t_id, $t_def['type'])
+			) {
+			if(!isset($t_old_custom_field_value)) {
+				error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) );
+				trigger_error( ERROR_EMPTY_FIELD, ERROR );
+			}
 		}
 
 		$t_new_custom_field_value = gpc_get_custom_field( "custom_field_$t_id", $t_def['type'], '' );
-		$t_old_custom_field_value = custom_field_get_value( $t_id, $f_bug_id );
 
 		# Don't update the custom field if the new value both matches the old value and is valid
 		# This ensures that changes to custom field validation will force the update of old invalid custom field values
11684-2-bug_update.diff (1,561 bytes)   
bug11684-full.patch (5,221 bytes)   
diff -Naur mantisbt-1.2.3/bug_report.php mantisbt-patch/bug_report.php
--- mantisbt-1.2.3/bug_report.php	2010-09-27 16:11:01.000000000 +0200
+++ mantisbt-patch/bug_report.php	2010-09-27 16:09:38.000000000 +0200
@@ -104,18 +104,24 @@
 		$t_def = custom_field_get_definition( $t_id );
 
 		# Produce an error if the field is required but wasn't posted
-		if ( !gpc_isset_custom_field( $t_id, $t_def['type'] ) &&
-			( $t_def['require_report'] ||
-				$t_def['type'] == CUSTOM_FIELD_TYPE_ENUM ||
-				$t_def['type'] == CUSTOM_FIELD_TYPE_LIST ||
-				$t_def['type'] == CUSTOM_FIELD_TYPE_MULTILIST ||
-				$t_def['type'] == CUSTOM_FIELD_TYPE_RADIO ) ) {
+		if	(	$t_def['require_report']
+			&&	$t_def['type'] != CUSTOM_FIELD_TYPE_CHECKBOX
+			&&	!gpc_isset_custom_field($t_id, $t_def['type'])
+			) {
 			error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) );
 			trigger_error( ERROR_EMPTY_FIELD, ERROR );
 		}
-		if ( !custom_field_validate( $t_id, gpc_get_custom_field( "custom_field_$t_id", $t_def['type'], NULL ) ) ) {
-			error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) );
-			trigger_error( ERROR_CUSTOM_FIELD_INVALID_VALUE, ERROR );
+		if(gpc_isset_custom_field($t_id, $t_def['type'])) {
+			$t_custom_field_value = gpc_get_custom_field("custom_field_$t_id", $t_def['type'], NULL);
+			if	(	$t_def['display_report']
+				&&	!custom_field_validate(
+							$t_id,
+							$t_custom_field_value
+						) 
+				) {
+				error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) );
+				trigger_error( ERROR_CUSTOM_FIELD_INVALID_VALUE, ERROR );
+			}
 		}
 	}
 
@@ -135,13 +141,21 @@
 
 	# Handle custom field submission
 	foreach( $t_related_custom_field_ids as $t_id ) {
+		$t_def = custom_field_get_definition( $t_id );
 		# Do not set custom field value if user has no write access.
-		if( !custom_field_has_write_access( $t_id, $t_bug_id ) ) {
+		if	(	!$t_def['display_report']
+			||	!custom_field_has_write_access( $t_id, $t_bug_id )
+			) {
 			continue;
 		}
 
-		$t_def = custom_field_get_definition( $t_id );
-		if( !custom_field_set_value( $t_id, $t_bug_id, gpc_get_custom_field( "custom_field_$t_id", $t_def['type'], '' ), false ) ) {
+		$t_custom_field_value = gpc_get_custom_field( "custom_field_$t_id", $t_def['type'], '');
+		if	(	empty($t_custom_field_value)
+			&&	!$t_def['require_report']
+			) {
+			continue;
+		}
+		if(!custom_field_set_value($t_id, $t_bug_id, $t_custom_field_value, false)) {
 			error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) );
 			trigger_error( ERROR_CUSTOM_FIELD_INVALID_VALUE, ERROR );
 		}
diff -Naur mantisbt-1.2.3/bug_update.php mantisbt-patch/bug_update.php
--- mantisbt-1.2.3/bug_update.php	2010-09-27 16:10:52.000000000 +0200
+++ mantisbt-patch/bug_update.php	2010-09-27 16:09:33.000000000 +0200
@@ -137,19 +137,19 @@
 			continue;
 		}
 
+		$t_old_custom_field_value = custom_field_get_value( $t_id, $f_bug_id );
 		# Produce an error if the field is required but wasn't posted
-		if ( !gpc_isset_custom_field( $t_id, $t_def['type'] ) &&
-			( $t_def['require_' . $t_custom_status_label] ||
-				$t_def['type'] == CUSTOM_FIELD_TYPE_ENUM ||
-				$t_def['type'] == CUSTOM_FIELD_TYPE_LIST ||
-				$t_def['type'] == CUSTOM_FIELD_TYPE_MULTILIST ||
-				$t_def['type'] == CUSTOM_FIELD_TYPE_RADIO ) ) {
-			error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) );
-			trigger_error( ERROR_EMPTY_FIELD, ERROR );
+		if	(	$t_def['require_' . $t_custom_status_label]
+			&&	$t_def['type'] != CUSTOM_FIELD_TYPE_CHECKBOX
+			&&	!gpc_isset_custom_field($t_id, $t_def['type'])
+			) {
+			if(!isset($t_old_custom_field_value)) {
+				error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) );
+				trigger_error( ERROR_EMPTY_FIELD, ERROR );
+			}
 		}
 
 		$t_new_custom_field_value = gpc_get_custom_field( "custom_field_$t_id", $t_def['type'], '' );
-		$t_old_custom_field_value = custom_field_get_value( $t_id, $f_bug_id );
 
 		# Don't update the custom field if the new value both matches the old value and is valid
 		# This ensures that changes to custom field validation will force the update of old invalid custom field values
diff -Naur mantisbt-1.2.3/core/custom_field_api.php mantisbt-patch/core/custom_field_api.php
--- mantisbt-1.2.3/core/custom_field_api.php	2010-09-27 16:11:18.000000000 +0200
+++ mantisbt-patch/core/custom_field_api.php	2010-09-27 16:34:03.000000000 +0200
@@ -1172,12 +1172,11 @@
 			$t_valid &= ( $p_value == null ) || ( ( $p_value !== false ) && ( $p_value > 0 ) );
 			break;
 		case CUSTOM_FIELD_TYPE_CHECKBOX:
-			# Checkbox fields can hold a null value (when no checkboxes are ticked)
+		case CUSTOM_FIELD_TYPE_MULTILIST:
+			# These fields can hold a null value (when no values are selected)
 			if( $p_value === '' ) {
 				break;
 			}
-			# If checkbox field value is not null then we need to validate it... (note: no "break" statement here!)
-		case CUSTOM_FIELD_TYPE_MULTILIST:
 			$t_values = explode( '|', $p_value );
 			$t_possible_values = custom_field_prepare_possible_values( $row['possible_values'] );
 			$t_possible_values = explode( '|', $t_possible_values );
bug11684-full.patch (5,221 bytes)   
custom_field_api.php.diff (1,086 bytes)   
--- mantisbt-1.2.4\core\custom_field_api.php	2010-12-14 21:26:32.000000000 +0100
+++ mantis4\core\custom_field_api.php	2010-12-29 14:26:31.928750000 +0100
@@ -403,11 +403,12 @@
 
 	$t_custom_field_table = db_get_table( 'mantis_custom_field_table' );
 	$query = "INSERT INTO $t_custom_field_table
-					( name, possible_values )
+					( name, possible_values, default_value, valid_regexp )
 				  VALUES
-					( " . db_param() . ',' . db_param() . ')';
+					( " . db_param() . ',' . db_param() . ',' . db_param() . ',' . db_param() . ')';
+
+	db_query_bound( $query, Array( $c_name, '', '', '' ) );
 
-	db_query_bound( $query, Array( $c_name, '' ) );
 
 	return db_insert_id( $t_custom_field_table );
 }
@@ -1420,6 +1421,8 @@
 		}
 	}
 
+	$t_custom_field_value = string_attribute( $t_custom_field_value );
+
 	global $g_custom_field_type_definition;
 	if( isset( $g_custom_field_type_definition[$p_field_def['type']]['#function_print_input'] ) ) {
 		call_user_func( $g_custom_field_type_definition[$p_field_def['type']]['#function_print_input'], $p_field_def, $t_custom_field_value );
custom_field_api.php.diff (1,086 bytes)   

Relationships

related to 0011628 closeddhx Error 0001303 / Custom Field (Checkbox) evaluated as mandantory even when it is not 
has duplicate 0011850 closeddhx Mantis thinks custom fields are required when "Display When ...." fields are checked 
has duplicate 0011861 closedatrol Custom enum field marked as not mandatory is validated as mandatory 
has duplicate 0011869 closedatrol error reporting issues if user doesn't have write access to a custom field 
has duplicate 0011881 closedatrol Custom field required when reporting issue after upgrade 
has duplicate 0011918 closedatrol Can't create new issues since I created a list type custom field 
has duplicate 0011951 closedatrol Bug report page ask for custom fields not required nor displayed 
has duplicate 0011957 closedatrol Non required field is forced to fill in. 
has duplicate 0012115 closedatrol custom field is mandatory, although not configured to be so 
has duplicate 0012137 closedatrol Customer Fields causes problems with upgrading 
has duplicate 0012237 closedatrol bug of Validate the custom fields 
has duplicate 0012353 closedatrol Not requiered custom field got validated on new issue 
has duplicate 0012202 closedatrol Cannot update older issues after upgrading from 1.1.0 to 1.2.1. Get APPLICATION ERROR #11 
has duplicate 0012550 closedatrol custom field required, but not configured as required 
has duplicate 0012572 closedatrol Multiselection custom field is required even when marked to not be 
has duplicate 0012619 closedvboctor Custom fields are reported as required after upgrade from 1.1.0 to 1.2.3 
has duplicate 0012753 closedatrol Enumerate custom fields always required 
related to 0013406 closeddregad Default values for custom fields are not written to database 
related to 0016020 closeddregad Port Fix of 0011684 to master branch 

Activities

dhx

dhx

2010-03-19 11:28

reporter   ~0024821

The list, radio and enum custom field types cannot currently hold a null value. This is why bug_report.php is complaining about the list field having an empty value. Maybe we should allow for null values in these fields and we'll simply print a label like "Undefined" when a value hasn't yet been set?

david_s_nl

david_s_nl

2010-04-02 17:12

reporter   ~0025003

Sounds OK to me.. printing the label "Undefined", i assume you are talking about the manage custom field page.

FYI:
As far as i can see, in 1.2.0 the fields cannot hold a null value either, but this problem doesn't occur.

pramsent

pramsent

2010-04-26 05:26

reporter   ~0025261

Last edited: 2010-04-26 05:30

i have the very same problem with the version 1.2.1. is there any quick fix or patch?

pramsent

pramsent

2010-04-26 06:59

reporter   ~0025265

i tried to find a workaround by supplying default values, but if the user does not have write access he has no chance to report a bug.

pramsent

pramsent

2010-04-26 08:52

reporter   ~0025267

I found a workaround: Downgrade to 1.2.0! I believe that these are side effects from 0011628

ldsandon

ldsandon

2010-04-30 11:29

reporter   ~0025355

I have a custom field "Affected versions" defined as "=released_versions". This field is used to signal which versions are affected by a given issue beyond the one the bug is reported against. Given it's declaration, it is difficult to set a default without inserting a dummy release for each project, having NULL values in such fields like lists or enum should be OK - it's a missing value.
And I can confirm this didn't happen in 1.2.0, it started to happen in 1.2.1

jurgenhaas

jurgenhaas

2010-05-11 15:35

reporter   ~0025478

Same error here and I'm confused why the field should ever get a NULL value when a default value is defined.

djcarr

djcarr

2010-05-17 20:34

reporter   ~0025526

We also encountered this bug after upgrading from 1.1.6 to 1.2.1.

We have a custom Enumeration type No|Yes. Default value No. Required on Report unchecked. Display on Report also unchecked.

The use case is that this enumeration type would default to No and only be set to Yes later by developers. Thus it is not required when reporting.

The workaround for this error message in Mantis 1.2.1 is to check "Display on Report", this serves to populate the custom field with the default value and thus it passes validation. However this is not ideal as reporters have nothing to do with this field.

djcarr

djcarr

2010-05-19 01:49

reporter   ~0025539

Could this please be targetted to 1.2.2? It's quite annoying for users, first when they encounter an inability to report an issue, and then again when the Report Issue screen becomes cluttered with custom fields they don't use.

Sergiodf

Sergiodf

2010-05-21 17:53

reporter   ~0025585

I reported a duplicate of this bug and attached a patch in 0011951.

djcarr

djcarr

2010-05-23 20:23

reporter   ~0025592

Last edited: 2010-05-23 20:26

Thanks Sergiodf. I can confirm the patch in 0011951 worked for me. Hope it gets incorporated in the next Mantis release too.

(perhaps this issue could be updated to block severity and have the patch attached?)

djcarr

djcarr

2010-05-26 22:43

reporter   ~0025615

Last edited: 2010-05-26 23:03

Spoke too soon... After applying the patch I'm seeing a situation where an Enumeration type of No|Yes, default value No, Display Report = no, Required on report = no, is now triggering a different error, which is the second ERROR_CUSTOM_FIELD_INVALID_VALUE instance, ie in the code:

    if( !custom_field_set_value( $t_id, $t_bug_id, gpc_get_custom_field( "custom_field_$t_id", $t_def['type'], '' ), false ) ) {
        error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) );
        trigger_error( ERROR_CUSTOM_FIELD_INVALID_VALUE, ERROR );
    }

The issue is still submitted, however the error leads the user to think it wasn't.

Sergiodf

Sergiodf

2010-05-27 11:07

reporter   ~0025619

I have attached a new patch. I hope this time solves your situation, djcarr.

dhx

dhx

2010-05-29 10:51

reporter   ~0025625

Here is what I posted to the mailing list:

Many custom field types in MantisBT are sets[1] (mathematics: set
theory). Usually a set can be an empty set[2] and this is true for
certain MantisBT field types including checkbox and multilist. The
problem is that HTML UI controls for enumeration, list and radio field
types do not allow the user to specify an empty set. In other words, the
user is unable to undo their selection of a radio item to make the value
of the field undefined. Once they click on a radio option they're forced
into selecting one of the options even if they no longer want to commit
to any of the choices.

Users should be modifying their custom fields to add a new option
"Undefined" or "Not specified" (or similar terminology to represent an
empty set/null). This null value can then be selected by default on the
bug report page if you want to allow users to easily ignore it when
posting a bug.

However I do NOT recommend adding an "Undefined" option as it is a sign
that you're using the wrong type of field for the wrong task. Radio
fields are meant to contain items that are mutually exclusive where the
user has to select exactly ONE option from the list[3]. In other words,
they're not designed to hold a null value.

List and enumeration fields are basically the same mathematical concept
as the radio field (mutually exclusive options, select exactly one). The
only real difference with these field types is determining which UI
control will be used to present the options to the user.

I do agree that there is a need for a field which is a set of mutually
exclusive options where the user can select either the emtpy set OR one
of the options from the set. However I don't see how we can achieve that
without combining multiple UI field types together (a checkbox to toggle
whether the field is an empty set or not) or using JavaScript to
redefine how UI controls work (this is neither robust or accessible to
users).

[1] http://en.wikipedia.org/wiki/Set_%28computer_science%29

[2] http://en.wikipedia.org/wiki/Empty_set

[3] http://www.useit.com/alertbox/20040927.html

dhx

dhx

2010-05-29 10:54

reporter   ~0025626

The follow up to my comment on the mailing list was that we need to document things clearer so that administrators understand that the "require" checkbox has no effect on radio/list/enum fields. If the "display" checkbox is not checked on reporting an issue, you MUST provide a default value for the field.

I've assigned this issue to myself and I'll do what I can to make it easier for users to understand.

djcarr

djcarr

2010-05-30 19:05

reporter   ~0025628

Last edited: 2010-05-30 19:07

That's fair enough, but my experience of this issue is that the error still occurs even when you DO provide a default value for the field. Scenario was: "Custom Enumeration type No|Yes. Default value No. Required on Report unchecked. Display on Report also unchecked." - this configuration worked in previous versions, and is a very valid and common end user scenario. So this to me falls under the definition of a regression. I can see from the mailing list that it may be getting confused with the separate logistical issue that occurs when a default value is not provided.

djcarr

djcarr

2010-05-30 19:58

reporter   ~0025629

Last edited: 2010-05-30 20:16

Sergiodf's latest patch does work for me, though I should mention that it simply allows the still-undefined types to proceed through the Report Bug validation. On the Bug View page, the custom fields will have no value (blank). This also probably means they won't obey filters in the way one would expect. It is only once you edit the bug that you will see the custom fields populated with their defaults, and when you save the bug again they are finally persisted.

Is it possible in the Report Bug screen to have hidden fields that populate the undisplayed custom fields with their default values, so that the validation will succeed, AND the default values get stored to the bug?

Sergiodf

Sergiodf

2010-05-30 22:39

reporter   ~0025630

I don't think hidden fields is a good idea, because you can not trust on http post sent by client (it could have been modified).
But we can get default values from custom field definitions and store that values.

xbromy

xbromy

2010-06-02 08:59

reporter   ~0025661

Hi, we have the same prob with 1.2.1. Enum Ja|Nein with Nein as default. No Display on Report, No required on Report. Then we get the error. It only works with: See on Report and the writeAccess to Reporter. The the box showes and Nein ist selected and written to the issue... would be fine to see fixed in next release... store the default to the issue when the user can't access or see the field on the page..

crazya

crazya

2010-06-03 09:56

reporter   ~0025679

So...
one question:

Why empty multilists work fine in mantis 1.1.8?
I just don't get it :/

crazya

crazya

2010-06-04 09:01

reporter   ~0025701

Last edited: 2010-06-04 09:02

part of the patch:
if ( $t_def['require_report']
&& ( $t_def['type'] == CUSTOM_FIELD_TYPE_ENUM
|| $t_def['type'] == CUSTOM_FIELD_TYPE_LIST
|| $t_def['type'] == CUSTOM_FIELD_TYPE_MULTILIST
|| $t_def['type'] == CUSTOM_FIELD_TYPE_RADIO
)
&& !gpc_isset_custom_field( $t_id, $t_def['type'] )
) {
error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) );
trigger_error( ERROR_EMPTY_FIELD, ERROR );
}

That makes no sense.
Now you just get the error if the field has no value AND the field is one of the four problem fields. Average custom fields which you define for 'being not empty on report' are ignored.

Why don't you just kill the special fields in the if()?

Somethink like the following works fine for me:
if ( $t_def['require_report']
&& !gpc_isset_custom_field( $t_id, $t_def['type'] )
) {
error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) );
trigger_error( ERROR_EMPTY_FIELD, ERROR );
}

Maybe i didn't get it, but that makes more sense to me:)
Thx for the patch btw :)

Sergiodf

Sergiodf

2010-06-04 09:40

reporter   ~0025704

You are right, crazya. I realized yesterday after hour.

Sergiodf

Sergiodf

2010-06-04 09:44

reporter   ~0025705

We should consider the special case of CUSTOM_FIELD_TYPE_CHECKBOX, where emptyness is a valid selection.
I had problems with checkboxes before and had to remove al 'required' for custom fields of this type.

Sergiodf

Sergiodf

2010-06-04 10:39

reporter   ~0025707

New patch: 11684-2.diff
Run against original 1.2.1 file.

dominik

dominik

2010-06-23 07:54

reporter   ~0025962

Temporary workaround: Add additional value to custom field (eg. "undefined") and set this value as "default value"

icksde

icksde

2010-06-29 03:44

reporter   ~0025989

Hi, i have the same Problem and found the same code like crazya. I have changed it nearly like crazya but only error message changed to validation error.

This code and also dominiks workaround only works if the field is displayed at reporting :(

highmqn

highmqn

2010-06-30 07:34

reporter   ~0025999

Hi, it seems like I have the same issue when updating a issue. Could it be related ?

Sergiodf

Sergiodf

2010-06-30 09:05

reporter   ~0026000

Yes, highmqn, it is the same problem.
I attach 11684-2-bug_update.diff to patch bug_update.php similar to 11684-2.diff.

This validations should be in a function instead of copied in every file.

highmqn

highmqn

2010-06-30 09:45

reporter   ~0026001

Thanks a lot ! Does the problem still appears when the custom field is not displayed ?

tps123

tps123

2010-06-30 14:56

reporter   ~0026004

Just to be clear does Sergiodf patch resolve this issue?

basically this bug should have the highest possible priority since it basically as made all installations of Mantis 1.2.1 that uses custom fields non functional.

markretallack

markretallack

2010-07-30 03:48

reporter   ~0026173

Good morning,

I have just updated our test server with 1.2.2 to check if this issue was fixed and I can reproduce it.

The problem is that we have a Custom Enumeration type called "Test On Site?" that has the values "No|Yes" and a default value "No". The "Required on Report" field is unchecked and "Display When Reporting Issues" is also unchecked.

However when a new issue is raised, the error:

"A necessary field "Test On Site?" was empty. Please recheck your inputs."

is reported. We are still running 1.2.0 after finding the issue in the 1.2.1 release.

Is there a workaround?

Mark Retallack.

PS. thanks for all the hard work that has gone into creating Mantis.

Sergiodf

Sergiodf

2010-07-30 11:53

reporter   ~0026179

markretallack, you can try applying 11684-2.diff (and eventually 11684-2-bug_update.diff).
No other solutions up to now.

bbogovich

bbogovich

2010-08-03 18:58

reporter   ~0026208

I had this problem after upgrading from 1.2.0 to 1.2.1. I was able to get it working again by modifying the core/custom_field_api.php, bug_report.php and bug_update.php files.

Changes:
core/custom_field_api.php
The validation checks for multilist, enum, list and radio needed changed to allow empty values. This was needed to fix an "invalid data" error after the field required logic was corrected.

Diff (against 1.2.1 release):
1177a1178,1180

      if( $p_value === '' ) {
          break;
      }

1186a1190,1192
if( $p_value === '' ) {
break;
}

bug_update.php
The required field test in 1.2.1 is incorrect and will always return true for custom enum, list, multilist and radio fields. The custom value assignment also needed changed to null (someone please confirm that this won't break anything)
Diff (against 1.2.1 release):
142c142
< ( $tdef['require' . $t_custom_status_label] ||

      $t_def['require_' . $t_custom_status_label] && (

150,151c150
<
< $t_new_custom_field_value = gpc_get_custom_field( "customfield$t_id", $t_def['type'], '' );

  $t_new_custom_field_value = gpc_get_custom_field( "custom_field_$t_id", $t_def['type'], null );

bug_record.php
The same logic error from bug_update.php is present in bug_report.php.

Diff (against 1.2.1 release):
108c108
< ( $t_def['require_report'] ||

       $t_def['require_report'] &&(
nimmich

nimmich

2010-08-04 13:31

reporter   ~0026213

@dhx: Selecting empty values in enumerations/lists and deselecting all entries in a multilist are IHMO perfect and valid methods to express an empty set in HTML UI controls. Even mantis makes use of this, e. g. in several version list boxes.

However, I don't see this as an UI issue. If the admin decided that a field isn't required then there's always the possibility of a default NULL/undecided value, and mantis should be able to handle that.

This is an absolute showstopper for us to work with mantis > 1.2.0. We have several enumeration fields that are only required under special circumstances, so the default value is empty - and this doesn't work anymore.

dhx

dhx

2010-08-09 05:37

reporter   ~0026246

@nimmich: you can't deselect a selection you've made in a combo box (enumeration) or list control. As such you'll need to add an "Unspecified" option to your radio/list/enumeration custom field possible values string. You'll also need to change the default value of the custom field to match the newly added "Unspecified" string. You can then safely turn off the "require" checkbox for certain pages and not worry about the user leaving the field blank (it'll use the default value instead).

You can deselect all options in a multiple-selection list control therefore MantisBT 1.2.x allows null values for the multilist custom field type.

macarbiter

macarbiter

2010-08-23 16:48

reporter   ~0026428

@dhx: By now requiring that a new enumeration entry of "Unspecified" or "Undefined" or whatever be created is firstly not very elegant, and secondly causes a further problem for us.

We have a custom enumeration that is not required or displayed when reporting an issue, but is required when updating it. This is because the value is not known at the time you log the issue, but will be known when you update it later.

If the default value of the enumeration is empty/null, then when you log it, it will not have any value, but when you update it, you will be forced to select a value.

However, if you have a default value of "Unspecified", there will be no way to force the person updating the issue to change that value as it is a valid value and therefore passes the 'required' test. This allows an issue to flow the entire workflow and still have this value set at "Unspecified" because there was no forced requirement to change it.

If an empty or null value was once again allowed (as it was in previous versions) then you would once again be able to only force a value to be populated later in the process.

macarbiter

macarbiter

2010-08-23 17:12

reporter   ~0026429

I would also like to add that even if you use a default value of "Unspecified", this has absolutely no effect when the field is not displayed on the report page. An empty value is still set, which then causes the issue to fail. The only way around this is to display each and every enumeration field on the report page, which unnecessarily clutters up the report page.

KarlReichert

KarlReichert

2010-08-24 03:34

reporter   ~0026440

macarbiter is right, I can confirm that use case (we have the same in my company's project) and the problem, that now every custom field must be visible on bug submit page, which confuses a lot of users, as they don't know what to enter here.

dasomerville@sherwin.com

dasomerville@sherwin.com

2010-08-25 10:07

reporter   ~0026469

I am getting this after the upgrade as well. I am currently on 1.2.1.

picochip

picochip

2010-08-25 11:24

reporter   ~0026470

I have to agree with the last three notes. We are finding this issue is a complete showstopper for updating to the latest Mantis version.
Is there anything we can do to help the development of a fix for this?
Thanks,
Andy

djcarr

djcarr

2010-08-25 19:16

reporter   ~0026472

I wonder if we can turn our thoughts to the solution here. My thoughts run along the lines of:

  1. When a new issue is submitted, the validation process should first cycle through the displayed fields (which would have been pre-populated with default values anyway, so they are usually going to be valid.)
  2. The validation should then cycle through the non-displayed fields and assign default values to them where available
  3. Where a default value isn't available, null is accepted as a valid value and the issue allowed to proceed. It doesn't seem feasible to disallow null entirely because there are so many ways that null values can enter Mantis - through imports, db upgrades, adding or removing custom fields, etc. However, Mantis can be designed to be biased against null values so that they don't occur very often.
sveyret

sveyret

2010-09-27 10:42

reporter   ~0026873

Hi all,

Sergiodf, there is something missing in you patch. For an empty multiselection list, when modifying a bug, the empty value is forbidden, which does not make sense, because we should be able to select nothing.

There is a small correction to do in custom_field_api.php. I added a new patch, containing both corrections of Sergiodf + the correction in custom field api (to be applied with “patch -p1”).

Hope this will help.

cproensa

cproensa

2010-10-11 08:12

developer   ~0027006

Last edited: 2010-10-11 08:14

Sometimes there's the need of displaying a combo list for a custom field, which is required, and without a default value, so the user is forced to select one of the items. Even better if it displayed a "select a value from the list" default item (not selectable itself...)

So...i think:
if a "blank" selection is not in the valid items for the selection list, it should not validate.
OR make it as a configuration option for the custom field: "null field is valid selection"
OR adding regexp validation for advanced control (by the way, discarded on 0011610)

istvanb

istvanb

2010-10-30 06:31

reporter   ~0027201

I understand that certain types can not store a NULL value. In the other hand if I set a default value to the field I somewhat thought that the default value will be applied.

If the field is assigned to that certain project then it has to be created when the issue is created (with the default value if it is not displayed or not required). Later on let say when the issue is updated the field should show the current value. I dont know how complicated it is to code, but I think this would resolve the problem.

I agree with the comments above, this is a major inconvenience now.

dhx

dhx

2010-10-30 09:10

reporter   ~0027202

There was a recent commit (for an upcoming 1.2.4 release) recently which should solve a number of problems related to custom fields (especially on the update page). See: http://git.mantisbt.org/?p=mantisbt.git;a=commitdiff;h=76c9a79ef7d88a135e226088c167e90065ef9277

llattan

llattan

2010-11-15 15:55

reporter   ~0027369

I am currently on 1.2.3
The problem is still happening.

dandjo

dandjo

2010-11-22 11:26

reporter   ~0027451

Same here, 1.2.3 and still happening.

This behavior (not accepting null values) makes the flag "required" in the "Manage Custom Fields" section a bit useless. I cannot leave the field empty, so it is the same as I configure the field "required".

dandjo

dandjo

2010-11-22 11:42

reporter   ~0027452

Same in 1.3.0 nightly versions.

macarbiter

macarbiter

2010-11-25 04:21

reporter   ~0027486

Is there any indication when this will be fixed or at least a working patch file for 1.2.3 will be available?

We embarked on a process to get Mantis 1.2 rolled out to our whole company after we had been successfully using 1.1 for the last few years. However, this bug has caused a major set-back on this roll-out, and the choice to go with Mantis is starting to be second guessed.

andy778

andy778

2010-12-07 09:54

reporter   ~0027566

I also noticed this now in our mantis 1.2.3 and this is somewhat a showstopper for us. Have this been planned to be fixed in 1.2.4?

dhx

dhx

2010-12-18 20:44

reporter   ~0027643

Victor Boctor attached a patch in 0012619 for those who don't like this behavior.

z00l00k

z00l00k

2010-12-29 08:58

reporter   ~0027748

I have added a patch I have done to take care of the problem.

It inserts empty strings in the fields that are declared "NOT NULL", which seems to be sufficient.

vboctor

vboctor

2011-01-09 03:11

manager   ~0027861

@Sergiodf, @dhx and others. I've done a check-in based on a fix that I did before knowing about this issue. When I inspected Sergiodf's patch, I found that he has more changes. Please validate my fix / latest and feel free to provide a patch on top.

I hope that my fix unblocks the majority of the users (if not all). However, if there are other changes that are necessary to completely handle the regression, then let us get it in before 1.2.5 is released.

See the attached changeset (890c36eb) for more details.

dhx

dhx

2011-01-09 03:34

reporter   ~0027862

@vboctor, thanks for reverting the change of functionality in 1.2.x - I can confirm that your changes look OK.

We can work on improving custom field validation/etc in a later major version of MantisBT.

Sergiodf

Sergiodf

2011-01-10 12:52

reporter   ~0027871

I tried vboctor's patch but it does not work with custom fields of type "List" having a default value defined but unchecking "Display When Reporting Issues".

In my installation, I have a field where the only boxes checked are "Display When Closing Issues" and "Required On Close" (this field is used only when closing an issue). Using vboctor's patch, it is not possible to submit a new issue.

vboctor

vboctor

2011-01-10 13:06

manager   ~0027872

@Sergiodf, did you apply both my patches? I did a follow up patch soon after the first one that should probably fix the issue you mentioned.

Sergiodf

Sergiodf

2011-01-10 14:03

reporter   ~0027873

You are right, Victor. I did not apply the "follow up patch".
Now, with both patches, I tried to report an issue and then to update it. It worked in both cases.

vboctor

vboctor

2011-01-10 15:23

manager   ~0027874

Should we mark this issue as resolved then? Any objections? If we are to revisit the change of behavior for 1.3.x, then we should open a new feature request and link to this one.

Sergiodf

Sergiodf

2011-01-10 15:55

reporter   ~0027877

This issue should be marked as resolved, in my opinion.

cjm1

cjm1

2011-01-26 03:56

reporter   ~0028082

We're seeing the same problem in 1.2.4 and a quick check of the attached patch diffs against the source we've installed suggests that the patch didn't make it into the 1.2.4 release.

atrol

atrol

2011-01-26 04:19

developer   ~0028083

cjm1, the fixed and target version is set to 1.2.x which means that the fix will be available with next version 1.2.5
If you want this now, you can download a nightly build from www.mantisbt.org/builds

cjm1

cjm1

2011-01-26 04:28

reporter   ~0028084

Sorry...my bad. For some reason I missed 1.2.4 being released and as I'd only just seen it assumed it was new in the last few days, rather than being released before the patch became available.

dissi

dissi

2011-02-20 11:01

reporter   ~0028260

Thanks to vboctor for fixing this issue.

But in one case it hasn't worked very well:
If a custom field was designed with write access for at least developer-level and additionally this field was mandatory for reporting a new issue a
reporter-level user writing a new issue, received an error message, that he has to fill the custom field.

I expanded the patch from vboctor to fix this remaining issue so therefore I hope that the application may now work appropriate.

bug_report.php from line 101 based on master-1.2.x 890c36eb

Validate the custom fields before adding the bug.

$t_related_custom_field_ids = custom_field_get_linked_ids( $t_bug_data->project_id );
foreach( $t_related_custom_field_ids as $t_id ) {

Do not set custom field value if user has no write access.

if (!custom_field_has_write_access_to_project($t_id, $t_bug_data->project_id)) {
    continue;
}

$t_def = custom_field_get_definition( $t_id );
# Produce an error if the field is required but wasn't posted.
if ( !gpc_isset_custom_field( $t_id, $t_def['type'] ) &&
    ( $t_def['require_report'] ) ) {
    error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) );
    trigger_error( ERROR_EMPTY_FIELD, ERROR );
}
if ( !custom_field_validate( $t_id, gpc_get_custom_field( "custom_field_$t_id", $t_def['type'], NULL ) ) ) {
    error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) );
    trigger_error( ERROR_CUSTOM_FIELD_INVALID_VALUE, ERROR );
}

}

Allow plugins to pre-process bug data

$t_bug_data = event_signal( 'EVENT_REPORT_BUG_DATA', $t_bug_data );

Create the bug

$t_bug_id = $t_bug_data->create();

Mark the added issue as visited so that it appears on the last visited list.

last_visited_issue( $t_bug_id );

Handle the file upload

if ( !is_blank( $f_file['tmp_name'] ) && ( 0 < $f_file['size'] ) ) {
file_add( $t_bug_id, $f_file, 'bug' );
}

Handle custom field submission

foreach( $t_related_custom_field_ids as $t_id ) {

Do not set custom field value if user has no write access.

if( !custom_field_has_write_access( $t_id, $t_bug_id ) ) {
    continue;
}

$t_def = custom_field_get_definition( $t_id );
if (gpc_isset_custom_field( $t_id, $t_def['type'] )) {
    if( !custom_field_set_value( $t_id, $t_bug_id, gpc_get_custom_field( "custom_field_$t_id", $t_def['type'], '' ), false ) ) {
        error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) );
        trigger_error( ERROR_CUSTOM_FIELD_INVALID_VALUE, ERROR );
    }
}

}

bug_update.php from line 150 based on master-1.2.x 890c36eb

Don't update the custom field if the new value both matches the old value and is valid

This ensures that changes to custom field validation will force the update of old invalid custom field values

if( $t_new_custom_field_value == $t_old_custom_field_value &&
custom_field_validate( $t_id, $t_new_custom_field_value ) ) {
continue;
}

atrol

atrol

2011-02-20 11:14

developer   ~0028261

dissi, please enter a new issue for this problem and attach your patch.
See http://www.mantisforge.org/dev/manual/en/developers/dev.contrib.submit.html#DEV.CONTRIB.SUBMIT.PATCH for the recommended way.

Related Changesets

MantisBT: master-1.2.x 890c36eb

2011-01-09 03:00

vboctor


Details Diff
Issue 0012619: Custom fields are reported as required after upgrade from 1.1.0 to 1.2.3.
Issue 0011684: Incorrect error "A necessary field "MyField" was empty. Please recheck your inputs." when submitting new issue.

There is a lot of details about this issue in issue 0011684. In 1.2.1 a breaking change was introduced which blocks users from submitting / updating issues for projects with certain custom field configurations. The aim of this fix is to unblock these users. We can do follow up fixes to improve on this for 1.2.x or to come up with the alternative strategy for 1.3.x. The goal is to come up with an approach that doesn't break existing users. The worst thing is that users upgrade and then find out that they can continue to use the product. If there is a path for upgrade to avoid these issues, then we should automate it as part of the upgrade script.

I haven't marked the issue as completely fixed until dhx checks it out, since he was working on the issue. I've used my fix for 0012619 + one more fix for the update code path. When I compared my fix to the attached patches, I note that the patches have more changes to handle things like special cases for checkboxes and the case where user doesn't have read-write. We may incorporate these after we do the necessary validations. Thanks for Sergiodf for contributing the patches.
Affected Issues
0011684, 0012619
mod - bug_report.php Diff File
mod - bug_update.php Diff File
mod - core/custom_field_api.php Diff File

MantisBT: master-1.2.x 7ab6eb38

2011-01-09 03:23

vboctor


Details Diff
Follow up fix for:

Issue 0012619: Custom fields are reported as required after upgrade from 1.1.0 to 1.2.3.
Issue 0011684: Incorrect error "A necessary field "MyField" was empty. Please recheck your inputs." when submitting new issue.
Affected Issues
0011684, 0012619
mod - core/custom_field_api.php Diff File

MantisBT: master 3d969053

2013-06-19 21:31

dregad


Details Diff
Fix 0016020: allow empty required custom fields

This is a port of the following 1.2.x commits:
- 890c36eb616cf5f1d115efa8b5de61b8b737937a
- 7ab6eb383a29a73ad65ade7de504d45477c87fb3

See related issues 0012619, 0011684 for details
Affected Issues
0011684, 0012619, 0016020
mod - bug_report.php Diff File
mod - core/custom_field_api.php Diff File