Skip to content

Commit 5a83346

Browse files
committed
Fix Checkbox id for library inclusion
1 parent 0da08b7 commit 5a83346

File tree

1 file changed

+46
-37
lines changed

1 file changed

+46
-37
lines changed
Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
<?php
2-
32
namespace Ajax\semantic\html\modules\checkbox;
43

54
use Ajax\semantic\html\base\HtmlSemDoubleElement;
65
use Ajax\semantic\html\base\constants\CheckboxType;
76
use Ajax\JsUtils;
87

98
abstract class AbstractCheckbox extends HtmlSemDoubleElement {
10-
protected $_params=[];
119

12-
public function __construct($identifier, $name=NULL, $label=NULL, $value=NULL, $inputType="checkbox", $type="checkbox") {
13-
parent::__construct("ck-".$identifier, "div", "ui ".$type);
14-
$this->_identifier=$identifier;
15-
$field=new \Ajax\common\html\html5\HtmlInput($identifier, $inputType, $value);
10+
protected $_params = [];
11+
12+
public function __construct($identifier, $name = NULL, $label = NULL, $value = NULL, $inputType = "checkbox", $type = "checkbox") {
13+
parent::__construct("ck-" . $identifier, "div", "ui " . $type);
14+
$this->_identifier = $identifier;
15+
$field = new \Ajax\common\html\html5\HtmlInput($identifier, $inputType, $value);
1616
$field->setProperty("name", $name);
1717
$this->setField($field);
1818
if (isset($label))
19-
$this->setLabel($label,$value);
19+
$this->setLabel($label, $value);
20+
$this->setLibraryId($identifier);
2021
}
2122

22-
public function setChecked($value=true){
23-
if($value===true){
23+
public function setChecked($value = true) {
24+
if ($value === true) {
2425
$this->getField()->setProperty("checked", "checked");
25-
}else{
26+
} else {
2627
$this->getField()->removeProperty("checked");
2728
}
2829
return $this;
@@ -32,24 +33,26 @@ public function setType($checkboxType) {
3233
return $this->addToPropertyCtrl("class", $checkboxType, CheckboxType::getConstants());
3334
}
3435

35-
public function setLabel($label,$value=null) {
36-
$labelO=$label;
36+
public function setLabel($label, $value = null) {
37+
$labelO = $label;
3738
if (\is_string($label)) {
38-
$labelO=new HtmlSemDoubleElement("", "label", "");
39+
$labelO = new HtmlSemDoubleElement("", "label", "");
3940
$labelO->setContent($label);
40-
$labelO->setProperty("for", $this->getField()->getIdentifier());
41-
if(isset($value))
41+
$labelO->setProperty("for", $this->getField()
42+
->getIdentifier());
43+
if (isset($value))
4244
$labelO->setProperty("data-value", $value);
4345
}
44-
$this->content["label"]=$labelO;
46+
$this->content["label"] = $labelO;
4547
}
4648

4749
public function setField($field) {
48-
$this->content["field"]=$field;
50+
$this->content["field"] = $field;
4951
}
5052

5153
/**
5254
* Returns the label or null
55+
*
5356
* @return mixed
5457
*/
5558
public function getLabel() {
@@ -59,6 +62,7 @@ public function getLabel() {
5962

6063
/**
6164
* Return the field
65+
*
6266
* @return mixed
6367
*/
6468
public function getField() {
@@ -69,9 +73,9 @@ public function getField() {
6973
* puts the label before or behind
7074
*/
7175
public function swapLabel() {
72-
$label=$this->getLabel();
76+
$label = $this->getLabel();
7377
unset($this->content["label"]);
74-
$this->content["label"]=$label;
78+
$this->content["label"] = $label;
7579
}
7680

7781
public function setReadonly() {
@@ -81,28 +85,33 @@ public function setReadonly() {
8185

8286
/**
8387
* Attach $this to $selector and fire $action
84-
* @param string $selector jquery selector of the associated element
85-
* @param string $action action to execute : check, uncheck or NULL for toggle
88+
*
89+
* @param string $selector
90+
* jquery selector of the associated element
91+
* @param string $action
92+
* action to execute : check, uncheck or NULL for toggle
8693
* @return AbstractCheckbox
8794
*/
88-
public function attachEvent($selector, $action=NULL) {
89-
if (isset($action)||\is_numeric($action)===true) {
90-
$js='$("#%identifier%").checkbox("attach events", "'.$selector.'", "'.$action.'");';
95+
public function attachEvent($selector, $action = NULL) {
96+
if (isset($action) || \is_numeric($action) === true) {
97+
$js = '$("#%identifier%").checkbox("attach events", "' . $selector . '", "' . $action . '");';
9198
} else {
92-
$js='$("#%identifier%").checkbox("attach events", "'.$selector.'");';
99+
$js = '$("#%identifier%").checkbox("attach events", "' . $selector . '");';
93100
}
94-
$js=\str_replace("%identifier%", $this->identifier, $js);
101+
$js = \str_replace("%identifier%", $this->identifier, $js);
95102
return $this->executeOnRun($js);
96103
}
97104

98105
/**
99106
* Attach $this to an array of $action=>$selector
100-
* @param array $events associative array of events to attach ex : ["#bt-toggle","check"=>"#bt-check","uncheck"=>"#bt-uncheck"]
107+
*
108+
* @param array $events
109+
* associative array of events to attach ex : ["#bt-toggle","check"=>"#bt-check","uncheck"=>"#bt-uncheck"]
101110
* @return AbstractCheckbox
102111
*/
103-
public function attachEvents($events=array()) {
112+
public function attachEvents($events = array()) {
104113
if (\is_array($events)) {
105-
foreach ( $events as $action => $selector ) {
114+
foreach ($events as $action => $selector) {
106115
$this->attachEvent($selector, $action);
107116
}
108117
}
@@ -113,24 +122,24 @@ public function setFitted() {
113122
return $this->addToProperty("class", "fitted");
114123
}
115124

116-
public function setOnChecked($jsCode){
117-
$this->_params["onChecked"]=$jsCode;
125+
public function setOnChecked($jsCode) {
126+
$this->_params["onChecked"] = $jsCode;
118127
return $this;
119128
}
120129

121-
public function setOnUnchecked($jsCode){
122-
$this->_params["onUnchecked"]=$jsCode;
130+
public function setOnUnchecked($jsCode) {
131+
$this->_params["onUnchecked"] = $jsCode;
123132
return $this;
124133
}
125134

126-
public function setOnChange($jsCode){
127-
$this->_params["onChange"]=$jsCode;
135+
public function setOnChange($jsCode) {
136+
$this->_params["onChange"] = $jsCode;
128137
return $this;
129138
}
130139

131140
public function run(JsUtils $js) {
132-
if(!isset($this->_bsComponent))
133-
$this->_bsComponent=$js->semantic()->checkbox("#" . $this->identifier, $this->_params);
141+
if (! isset($this->_bsComponent))
142+
$this->_bsComponent = $js->semantic()->checkbox("#" . $this->identifier, $this->_params);
134143
return parent::run($js);
135144
}
136145
}

0 commit comments

Comments
 (0)