Make a field non required

Get help from other users here.

Moderators: Developer, Contributor

Post Reply
davew
Posts: 4
Joined: 09 May 2020, 17:33

Make a field non required

Post by davew »

Hi...

I'm trying to make the issues "description" field non mandatory, and to default to the same content as "summary"...
I've searched in here and tried this:

in bug_api.php:
if( $p_update_extended ) {
# Description field cannot be empty
// if( is_blank( $this->description ) ) {
// error_parameters( lang_get( 'description' ) );
// trigger_error( ERROR_EMPTY_FIELD, ERROR );
// }
}

and in bug_report.php:

$t_issue = array(
'project' => array( 'id' => $t_project_id ),
'reporter' => array( 'id' => auth_get_current_user_id() ),
'summary' => gpc_get_string( 'summary' ),
'description' => gpc_get_string( 'description',''),
);
if ( is_blank( $t_issue->description ) ) {
$t_issue->description = $t_issue->summary;
}

however, it doesn't work....

Any suggestions please?

Thanks!
cas
Posts: 1586
Joined: 11 Mar 2006, 16:08
Contact:

Re: Make a field non required

Post by cas »

Why remove the check?
In your bug_report.php, you already fill the description field if it is empty.
I would use the following line of code:
if ( trim($t_issue->description) == "" ) ) {
davew
Posts: 4
Joined: 09 May 2020, 17:33

Re: Make a field non required

Post by davew »

The change to bug_report.php made no difference. Mantis still insists on the field being entered, so the summary data never gets put into description.
So, the change to bug_api.php was to try and stop the requirement to enter data into description - the check has to be removed else the above change doesn't get a chance to work.

So - the problem is that both the changes I tried make *no difference at all* to how it works!
I still cannot save an issue without manually entering description data.

I should have said, this is Mantis 2.24.1

I've seen other people in here try and do this, but without success...

Any help appreciated!
cas
Posts: 1586
Joined: 11 Mar 2006, 16:08
Contact:

Re: Make a field non required

Post by cas »

Although rather not change core code, this should work:
Change this code (bug_report.php):

Code: Select all

$t_issue = array(
	'project' => array( 'id' => $t_project_id ),
	'reporter' => array( 'id' => auth_get_current_user_id() ),
	'summary' => gpc_get_string( 'summary' ),
	'description' => gpc_get_string( 'description' ),
); 
into:

Code: Select all

$t_sum=  gpc_get_string( 'summary' );
$t_desc=  trim(gpc_get_string( 'description' ));
if ($t_desc == ""){
	$t_desc= $t_sum;
}
$t_issue = array(
	'project' => array( 'id' => $t_project_id ),
	'reporter' => array( 'id' => auth_get_current_user_id() ),
	'summary' => $t_sum),
	'description' => $t_desc,
); 
I have not tried it but this should do the trick.
atrol
Site Admin
Posts: 8366
Joined: 26 Mar 2008, 21:37
Location: Germany

Re: Make a field non required

Post by atrol »

No time to have a deeper look, but I assume you are on the wrong track.
You have to remove "required" from the following line, to prevent browser from checking the empty textarea when pushing the "Submit Issue" button.

Code: Select all

<textarea class="form-control" <?php echo helper_get_tab_index() ?> id="description" name="description" cols="80" rows="10" required>
Please use Search before posting and read the Manual
cas
Posts: 1586
Joined: 11 Mar 2006, 16:08
Contact:

Re: Make a field non required

Post by cas »

You are right, missed the obvious as usual :lol:
davew
Posts: 4
Joined: 09 May 2020, 17:33

Re: Make a field non required

Post by davew »

Thanks atrol, but this is a bit odd.

I change line 574 in bug_report_page.php to:

Code: Select all

<textarea class="form-control" <?php echo helper_get_tab_index() ?> id="description" name="description" cols="80" rows="5">
It then alters the field to 5 rows - so it's affecting the right area - but it's still a required field!
The "*" is still there - it now allows the browser to proceed but then I get:
APPLICATION ERROR #11
A necessary field "description" was empty. Please recheck your inputs.
Please use the "Back" button in your web browser to return to the previous page. There you can correct whatever problems were identified in this error or select another action. You can also click an option from the menu bar to go directly to a new section.
So there's something else still affecting that... I thought my tweak to bug_api.php would have stopped the app error 11?
cas
Posts: 1586
Joined: 11 Mar 2006, 16:08
Contact:

Re: Make a field non required

Post by cas »

You also can set a default description in config_inc.php using this variable:
/**
* Default value for bug description field used on bug report page.
*
* @global string $g_default_bug_description
*/
$g_default_bug_description = 'See Summary';

All solved without any changes to the code :mrgreen:
davew
Posts: 4
Joined: 09 May 2020, 17:33

Re: Make a field non required

Post by davew »

cas - that's nifty - thanks! :)
Post Reply