Skip to content

Commit 9d46630

Browse files
committed
checkbox with label=false
1 parent 8aaaa73 commit 9d46630

File tree

5 files changed

+29
-4
lines changed

5 files changed

+29
-4
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@
33
## Breaking changes
44

55
- Layout classes must now implement `render_static`.
6+
- Layout for checkboxes changed, label is now called `text`.
67

78
## Bugfixes
89

910
- Unbuffered output regression fix since 1.1.0
1011
- Support static fields for all layouts.
1112

13+
## Features
14+
15+
- Checkboxes support label=false the same way other fields does.
16+
1217
# 1.1.0 (2016-05-29)
1318

1419
## Breaking changes

src/lib/FormCheckbox.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ public function __construct($key, $id, $name, $value, $type, $label, $attr) {
99
$this->name = $name;
1010
$this->label = $label;
1111
$this->hint = null;
12+
$this->text = '';
1213

1314
$this->pop_attr('hint', $attr, $this->hint);
15+
$this->pop_attr('text', $attr, $this->text);
1416

1517
if ( $type != null ) $attr['type'] = $type;
1618
if ( $id != null ) $attr['id'] = $id;
@@ -24,12 +26,14 @@ public function __construct($key, $id, $name, $value, $type, $label, $attr) {
2426
$this->attr = $attr;
2527
}
2628

29+
public function get_text(){
30+
return $this->text;
31+
}
2732

2833
public function get_content(array $extra_attr = array(), array $label = array()){
2934
$attr = array_merge_recursive($extra_attr, $this->attr);
30-
$text = $this->label;
3135
if ( $this->get_container() instanceof FormGroup ){
32-
return "<label " . FormUtils::serialize_attr($label) . "><input " . $this->serialize_attr($attr) . " />$text</label>";
36+
return "<label " . FormUtils::serialize_attr($label) . "><input " . $this->serialize_attr($attr) . " />{$this->text}</label>";
3337
} else {
3438
return "<input " . $this->serialize_attr($attr) . " />";
3539
}

src/lib/FormContainer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@ public function textarea($key, $label=null, array $attr=array()){
191191

192192
public function checkbox($key, $text, $label=null, array $attr=array()) {
193193
$this->hidden_field($key, '0');
194-
$this->fields[] = $this->factory('checkbox', $key, $text, $attr);
194+
$attr['text'] = $text;
195+
$this->fields[] = $this->factory('checkbox', $key, $label, $attr);
195196
}
196197

197198
public function fields_for($id, $obj, $method){

src/lib/FormLayoutBootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function render_field($field, $error){
2020
echo "<div class=\"checkbox\">";
2121
echo " <label for=\"$id\" class=\"control-label\">";
2222
echo " $content";
23-
echo " $label";
23+
echo " {$field->get_text()}";
2424
echo " </label>";
2525
if ( $hint ){
2626
echo " <span class=\"help-block\">$hint</span>";

src/lib/FormLayoutTable.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,26 @@ public function render_field($field, $error){
1010
$this->begin();
1111
}
1212

13+
$id = $field->get_id();
1314
$label = $field->get_label();
1415
$content = $field->get_content();
1516
$hint = $field->get_hint();
1617
$hints = $field->layout_hints();
1718

19+
if ( $field instanceof FormCheckbox ){
20+
echo " <tr>\n";
21+
if ( $label !== false ){
22+
echo " <th class=\"form-label\">{$field->get_text()}</th>\n";
23+
echo " <td class=\"form-field\">$content</td>\n";
24+
echo " <td class=\"form-hint\" >$hint</td>\n";
25+
echo " <td class=\"form-error\">$error</td>\n";
26+
} else {
27+
echo " <td class=\"form-field\" colspan=\"4\">{$content} {$field->get_text()}</td>\n";
28+
}
29+
echo " </tr>\n";
30+
return;
31+
}
32+
1833
if ( !($hints & Form::LAYOUT_TWOROWS) ){
1934
echo " <tr>\n";
2035
if ( $label !== false ){

0 commit comments

Comments
 (0)