Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Ensure checkbox labels are presented correctly on forms. (CO-2628) (#61)
arlen committed Mar 31, 2023
1 parent 010a08e commit adbe473
Showing 3 changed files with 50 additions and 14 deletions.
38 changes: 38 additions & 0 deletions app/src/Controller/StandardController.php
@@ -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.
*
@@ -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.
*
11 changes: 10 additions & 1 deletion app/src/View/Helper/FieldHelper.php
@@ -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;
@@ -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);
}

@@ -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>' : '') . '
15 changes: 2 additions & 13 deletions app/webroot/css/co-base.css
@@ -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) {
@@ -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;

0 comments on commit adbe473

Please sign in to comment.