Skip to content

Commit 460f9eb

Browse files
committed
widgets getFieldName moved
1 parent d551f2d commit 460f9eb

File tree

6 files changed

+28
-15
lines changed

6 files changed

+28
-15
lines changed

Ajax/common/Widget.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ public function setEdition($_edition=true) {
250250

251251
/**
252252
* Defines the default function which displays fields value
253-
* @param callable $defaultValueFunction. function parameters are : $name : the field name, $value : the field value ,$index : the field index, $instance : the active instance of model
253+
* @param callable $defaultValueFunction function parameters are : $name : the field name, $value : the field value ,$index : the field index, $instance : the active instance of model
254254
* @return \Ajax\common\Widget
255255
*/
256256
public function setDefaultValueFunction($defaultValueFunction){

Ajax/semantic/html/collections/HtmlGrid.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ public function __construct($identifier, $numRows=1, $numCols=NULL, $createCols=
3232
// }
3333
$this->setWide($numCols);
3434
}
35-
$this->setRowsCount($numRows, $numCols);
35+
if($createCols)
36+
$this->setRowsCount($numRows, $numCols);
3637
}
3738

3839
public function asSegment() {

Ajax/semantic/html/content/HtmlAbsractItem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function asLink($href=NULL,$part=NULL){
7777
* @see \Ajax\semantic\html\base\HtmlSemDoubleElement::compile()
7878
*/
7979
public function compile(JsUtils $js=NULL, &$view=NULL) {
80-
if(\is_array($this->content))
80+
if(\is_array($this->content) && JArray::isAssociative($this->content))
8181
$this->content=JArray::sortAssociative($this->content, [ "icon","image","content" ]);
8282
return parent::compile($js, $view);
8383
}

Ajax/semantic/widgets/base/FieldAsTrait.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Ajax\semantic\html\collections\form\HtmlFormCheckbox;
1212
use Ajax\semantic\html\collections\form\HtmlFormInput;
1313
use Ajax\semantic\html\collections\form\HtmlFormDropdown;
14+
use Ajax\semantic\html\collections\form\HtmlFormTextarea;
1415

1516
/**
1617
* @author jc
@@ -48,7 +49,7 @@ protected function _addRules($element,&$attributes){}
4849

4950
protected function _fieldAs($elementCallback,$index,$attributes=NULL,$prefix=null){
5051
$this->setValueFunction($index,function($value) use ($index,&$attributes,$elementCallback,$prefix){
51-
$name=$this->_instanceViewer->getCaption($index)."[]";
52+
$name=$this->_instanceViewer->getFieldName($index)."[]";
5253
if(isset($attributes["name"])){
5354
$name=$attributes["name"];
5455
}
@@ -127,6 +128,14 @@ public function fieldAsInput($index,$attributes=NULL){
127128
}, $index,$attributes,"input");
128129
}
129130

131+
public function fieldAsTextarea($index,$attributes=NULL){
132+
return $this->_fieldAs(function($id,$name,$value){
133+
$textarea=new HtmlFormTextarea($id,null,$value);
134+
$textarea->setName($name);
135+
return $textarea;
136+
}, $index,$attributes,"textarea");
137+
}
138+
130139
public function fieldAsHidden($index,$attributes=NULL){
131140
if(!\is_array($attributes)){
132141
$attributes=[];

Ajax/semantic/widgets/base/InstanceViewer.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,19 @@ public function getProperty($index){
126126
return $this->properties[$index];
127127
}
128128

129+
public function getFieldName($index){
130+
$property=$this->getProperty($index);
131+
if($property instanceof \ReflectionProperty){
132+
$result=$property->getName();
133+
}elseif(\is_callable($property)){
134+
$result=$this->visibleProperties[$index];
135+
}else{
136+
$result=$property;
137+
}
138+
return $result;
139+
}
140+
141+
129142
protected function showableProperty(\ReflectionProperty $rProperty){
130143
return JString::startswith($rProperty->getName(),"_")===false;
131144
}

Ajax/semantic/widgets/dataform/FormInstanceViewer.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,7 @@ protected function _beforeAddProperty($index,&$field){
3030
$field=\str_replace("\n", "", $field);
3131
}
3232

33-
public function getFieldName($index){
34-
$property=$this->getProperty($index);
35-
if($property instanceof \ReflectionProperty){
36-
$result=$property->getName();
37-
}elseif(\is_callable($property)){
38-
$result=$this->visibleProperties[$index];
39-
}else{
40-
$result=$property;
41-
}
42-
return $result;
43-
}
33+
4434

4535
public function addSeparatorAfter($fieldNum){
4636
if(\array_search($fieldNum, $this->separators)===false)

0 commit comments

Comments
 (0)