Skip to content

Ensure checkbox labels are presented correctly on forms. (CO-2628) #61

Merged
merged 1 commit into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions app/src/Controller/StandardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,21 @@ public function add() {
$this->render('/Standard/add-edit-view');
}

/**
* Standard operations before the view is rendered.
*
* @since COmanage Match v1.2.0
* @param EventInterface $event BeforeRender event
* @return \Cake\Http\Response HTTP Response
*/

public function beforeRender(\Cake\Event\EventInterface $event) {
// Provide some hints to the views
$this->getFieldTypes();

return parent::beforeRender($event);
}

/**
* Handle a delete action for a Standard object.
*
Expand Down Expand Up @@ -294,6 +309,29 @@ public function generateRedirect() {
return $this->redirect($redirect);
}

/**
* Make a list of fields types suitable for FieldHelper
*
* @since COmanage Match v1.2.0
*/

protected function getFieldTypes() {
// $this->name = Models (ie: from ModelsTable)
$modelsName = $this->name;
// $table = the actual table object
$table = $this->$modelsName;

$schema = $table->getSchema();

// We don't pass the schema object as is, partly because cake might change it
// and partly to simplify access to the parts the views (FieldHelper, really)
// actually need.

// Note the schema does have field lengths for strings, but typeMap
// doesn't return them and we're not doing anything with them at the moment.
$this->set('vv_field_types', $schema->typeMap());
}

/**
* Generate an index for a set of Standard Objects.
*
Expand Down
11 changes: 10 additions & 1 deletion app/src/View/Helper/FieldHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ public function control(string $fieldName,

$label = null;
$desc = null;

// Get the field type from the map of fields (e.g. 'boolean', 'string', 'timestamp')
$fieldMap = $this->getView()->get('vv_field_types');
$fieldType = $fieldMap[$fieldName];

if($labelText) {
$label = $labelText;
Expand Down Expand Up @@ -115,6 +119,11 @@ public function control(string $fieldName,
$control = $this->viewObj->$fieldName->nice();
$isRequired = false;
} else {
if($fieldType == 'boolean') {
// A boolean field is a checkbox. Include the label with the field.
$coptions['label'] = $label;
$coptions['class'] = 'form-check-input';
}
$control = $this->Form->control($fieldName, $coptions);
}

Expand All @@ -140,7 +149,7 @@ public function control(string $fieldName,
return '<li>
<div class="field-name">
<div class="field-title">
' . ($this->editable
' . ($this->editable && !($fieldType == 'boolean')
? $this->Form->label($fieldName, $label)
: $label)
. ($isRequired ? ' <span class="required">*</span>' : '') . '
Expand Down
15 changes: 2 additions & 13 deletions app/webroot/css/co-base.css
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,7 @@ ul.form-list li {
border-bottom: 1px solid var(--cmg-color-lightgray-005);
border-right: 1px solid var(--cmg-color-lightgray-005);
margin: 0;
padding: 0.5em;
padding: 0.8em 0.5em;
list-style: none;
}
ul.form-list li:nth-child(even) {
Expand Down Expand Up @@ -1097,19 +1097,8 @@ ul.form-list li.field-stack textarea {
width: 100%;
resize: vertical;
}
.checkbox {
margin-bottom: 0.5em;
}
.checkbox input {
float: left;
margin: 4px 4px 0 0;
}
.checkbox label {
margin-left: 1.5em;
display: block;
}
.checkbox label::first-line {
margin-left: 0;
margin: 0.25em 0.5em 0 0;
}
.checkbox .subfield {
margin-left: 1.5em;
Expand Down