Skip to content

Commit e0aff5f

Browse files
committed
FieldAsLabel
1 parent 4d236d2 commit e0aff5f

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

Ajax/semantic/widgets/base/FieldAsTrait.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Ajax\semantic\html\modules\checkbox\HtmlRadio;
99
use Ajax\semantic\html\base\constants\Size;
1010
use Ajax\semantic\widgets\datatable\InstanceViewer;
11+
use Ajax\semantic\html\elements\HtmlLabel;
1112

1213
/**
1314
* @author jc
@@ -19,6 +20,20 @@ trait FieldAsTrait{
1920
protected abstract function _getFieldIdentifier($prefix);
2021
public abstract function setValueFunction($index,$callback);
2122

23+
private function _getLabelField($caption,$icon=NULL){
24+
$label=new HtmlLabel($this->_getFieldIdentifier("lbl"),$caption,$icon);
25+
return $label;
26+
}
27+
28+
public function fieldAsLabel($index,$icon=NULL){
29+
$this->setValueFunction($index,function($caption) use($icon){
30+
$lbl=$this->_getLabelField($caption,$icon);
31+
return $lbl;
32+
}
33+
);
34+
return $this;
35+
}
36+
2237
public function fieldAsImage($index,$size=Size::SMALL,$circular=false){
2338
$this->setValueFunction($index,function($img) use($size,$circular){
2439
$image=new HtmlImage($this->_getFieldIdentifier("image"),$img);$image->setSize($size);if($circular)$image->setCircular();
@@ -52,7 +67,6 @@ public function fieldAsInput($index,$name=NULL,$type="text",$placeholder=""){
5267
$name=$this->_instanceViewer->getCaption($index)."[]";
5368
}
5469
$input->getField()->setProperty("name", $name);
55-
$input->setFluid();
5670
return $input;
5771
}
5872
);

Ajax/semantic/widgets/datatable/DataTable.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ private function _setToolbarPosition($table,$captions){
131131

132132
/**
133133
* Associates a $callback function after the compilation of the field at $index position
134-
* The $callback function can take the following arguments : $field=>the compiled field, $index: the field position, $instance : the active instance of the object
134+
* The $callback function can take the following arguments : $field=>the compiled field, $instance : the active instance of the object, $index: the field position
135135
* @param int $index postion of the compiled field
136136
* @param callable $callback function called after the field compilation
137137
* @return \Ajax\semantic\widgets\datatable\DataTable
@@ -352,7 +352,8 @@ public function getToolbar(){
352352
}
353353

354354
/**
355-
* @param unknown $element
355+
* Adds a new element in toolbar
356+
* @param mixed $element
356357
* @return \Ajax\common\html\HtmlDoubleElement
357358
*/
358359
public function addInToolbar($element){

Ajax/semantic/widgets/datatable/InstanceViewer.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public function __construct($instance=NULL,$captions=NULL){
2323
public function getCaption($index){
2424
if($this->properties[$index] instanceof \ReflectionProperty)
2525
return $this->properties[$index]->getName();
26+
elseif(\is_callable($this->properties[$index]))
27+
return "";
2628
else
2729
return $this->properties[$index];
2830
}
@@ -203,7 +205,7 @@ public function getProperties() {
203205

204206
/**
205207
* Associates a $callback function after the compilation of the field at $index position
206-
* The $callback function can take the following arguments : $field=>the compiled field, $index: the field position, $instance : the active instance of the object
208+
* The $callback function can take the following arguments : $field=>the compiled field, $instance : the active instance of the object, $index: the field position
207209
* @param int $index postion of the compiled field
208210
* @param callable $callback function called after the field compilation
209211
* @return \Ajax\semantic\widgets\datatable\InstanceViewer

0 commit comments

Comments
 (0)