Uncheck a couple boxes by default to match existing behavior

This commit is contained in:
Marcus Moore 2024-01-18 13:30:51 -08:00
parent 861ef6312e
commit 1630392953
No known key found for this signature in database
3 changed files with 6 additions and 5 deletions

View file

@ -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

View file

@ -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>

View file

@ -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()