Skip to content

A free open source IT asset/license management system

Uncheck a couple boxes by default to match existing behavior

Marcus Moore1630392953c3
diff --git a/app/Models/ReportTemplate.php b/app/Models/ReportTemplate.php
index b92a346932..6c8aa622fa 100644
--- a/app/Models/ReportTemplate.php
+++ b/app/Models/ReportTemplate.php
@@ -48,13 +48,13 @@ class ReportTemplate extends Model
return $this->belongsTo(User::class);
}
- public function checkmarkValue(string $fieldName): string
+ public function checkmarkValue(string $fieldName, string $fallbackValue = '1'): string
{
// Assuming we're using the null object pattern, and an empty model
// was passed to the view when showing the default report page,
- // return 1 so that checkboxes are checked by default.
+ // return the fallback value so that checkboxes are checked by default.
if (is_null($this->id)) {
- return '1';
+ return $fallbackValue;
}
// Return the field's value if it exists and return 0
diff --git a/resources/views/reports/custom.blade.php b/resources/views/reports/custom.blade.php
index afa13ceaff..6159f520b3 100644
--- a/resources/views/reports/custom.blade.php
+++ b/resources/views/reports/custom.blade.php
@@ -407,13 +407,13 @@
<div class="col-md-9 col-md-offset-3">
<label class="form-control">
- {{ Form::checkbox('exclude_archived', '1', $template->checkmarkValue('exclude_archived')) }}
+ {{ Form::checkbox('exclude_archived', '1', $template->checkmarkValue('exclude_archived', '0')) }}
{{ trans('general.exclude_archived') }}
</label>
</div>
<div class="col-md-9 col-md-offset-3">
<label class="form-control">
- {{ Form::checkbox('use_bom', '1', $template->checkmarkValue('use_bom')) }}
+ {{ Form::checkbox('use_bom', '1', $template->checkmarkValue('use_bom', '0')) }}
{{ trans('general.bom_remark') }}
</label>
</div>
diff --git a/tests/Unit/ReportTemplateTest.php b/tests/Unit/ReportTemplateTest.php
index 1f3976f5ac..55b9d47225 100644
--- a/tests/Unit/ReportTemplateTest.php
+++ b/tests/Unit/ReportTemplateTest.php
@@ -69,6 +69,7 @@ class ReportTemplateTest extends TestCase
$this->assertEquals('1', $template->checkmarkValue('is_a_checkbox_field'));
$this->assertEquals('0', $template->checkmarkValue('non_existent_key'));
$this->assertEquals('0', $template->checkmarkValue('is_checkbox_field_with_zero'));
+ $this->assertEquals('0', (new ReportTemplate)->checkmarkValue('non_existent_key', '0'));
}
public function testParsingTextValue()