Skip to content

Commit 24b2b85

Browse files
committed
form fields wrapper
1 parent 71a3fd6 commit 24b2b85

File tree

4 files changed

+50
-8
lines changed

4 files changed

+50
-8
lines changed

Ajax/semantic/traits/SemanticWidgetsTrait.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,8 @@ public function defaultLogin($identifier,$instance=null){
4545
public function smallLogin($identifier,$instance=null){
4646
return $this->addHtmlComponent(FormLogin::small($identifier,$instance));
4747
}
48+
49+
public function segmentedLogin($identifier,$instance=null){
50+
return $this->addHtmlComponent(FormLogin::attachedSegment($identifier,$instance));
51+
}
4852
}

Ajax/semantic/widgets/business/user/FormLogin.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ protected function getDefaultModelInstance(){
2020

2121
public static function regular($identifier,$modelInstance=null){
2222
return new FormLogin($identifier,$modelInstance,
23-
["message","login","password","remember","forget","submit"],
24-
["message"=>["icon"=>"sign in"],"input0"=>["rules"=>"empty"],"input1"=>["inputType"=>"password","rules"=>"empty"],"checkbox","link","submit"=>"green fluid"],
25-
["Connection","login","password","remember","forget","submit"],
23+
["message","login","password","remember","forget","submit","error"],
24+
["message"=>[["icon"=>"sign in"]],"input0"=>[["rules"=>"empty"]],"input1"=>[["inputType"=>"password","rules"=>"empty"]],"checkbox","link","submit"=>["green fluid"],"message2"=>[["error"=>true]]],
25+
["Connection","login","password","remember","forget","submit","error"],
2626
["Please enter login and password to connect","Login","Password","Remember me.","Forgot your password?","Connection"],
27-
[0,2,4,5]);
27+
[0,2,4,5,6]);
2828
}
2929

3030
public static function smallInline($identifier,$modelInstance=null){
3131
$result=new FormLogin($identifier,$modelInstance,
3232
["login","password","submit"],
33-
["input0"=>["rules"=>"empty"],"input1"=>["inputType"=>"password","rules"=>"empty"],"submit"=>"green basic"],
33+
["input0"=>[["rules"=>"empty"]],"input1"=>[["inputType"=>"password","rules"=>"empty"]],"submit"=>["green basic"]],
3434
["login","password","submit"],
3535
["","","Connection"],
3636
[2]);
@@ -41,11 +41,19 @@ public static function smallInline($identifier,$modelInstance=null){
4141
public static function small($identifier,$modelInstance=null){
4242
$result=new FormLogin($identifier,$modelInstance,
4343
["login","password","submit"],
44-
["input0"=>["rules"=>"empty"],"input1"=>["inputType"=>"password","rules"=>"empty"],"submit"=>"green basic"],
44+
["input0"=>[["rules"=>"empty"]],"input1"=>[["inputType"=>"password","rules"=>"empty"]],"submit"=>["green basic"]],
4545
["login","password","submit"],
4646
["Login","Password","Connection"],
4747
[1,2]);
4848
$result->addDividerBefore(0, "Connection");
4949
return $result;
5050
}
51+
52+
public static function attachedSegment($identifier,$modelInstance=null){
53+
$result=self::regular($identifier,$modelInstance);
54+
$result->fieldAsMessage("message",["icon"=>"sign in","attached"=>true]);
55+
$result->addWrapper("message",null,"<div class='ui attached segment'>");
56+
$result->addWrapper("error", null,"</div>");
57+
return $result;
58+
}
5159
}

Ajax/semantic/widgets/dataform/DataForm.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ protected function _generateContent($form){
5252
$count=$this->_instanceViewer->count();
5353
$separators=$this->_instanceViewer->getSeparators();
5454
$headers=$this->_instanceViewer->getHeaders();
55+
$wrappers=$this->_instanceViewer->getWrappers();
5556
\sort($separators);
5657
$size=\sizeof($separators);
5758
if($size===1){
@@ -61,15 +62,21 @@ protected function _generateContent($form){
6162
}else{
6263
$separators[]=$count;
6364
for($i=0;$i<$size;$i++){
65+
$wrapper=null;
6466
$fields=\array_slice($values, $separators[$i]+1,$separators[$i+1]-$separators[$i]);
6567
if(isset($headers[$separators[$i]+1]))
6668
$form->addHeader($headers[$separators[$i]+1],4,true);
69+
if(isset($wrappers[$separators[$i]+1])){
70+
$wrapper=$wrappers[$separators[$i]+1];
71+
}
6772
//TODO check why $fields is empty
6873
if(\sizeof($fields)===1){
69-
$form->addField($fields[0]);
74+
$added=$form->addField($fields[0]);
7075
}elseif(\sizeof($fields)>1){
71-
$form->addFields($fields);
76+
$added=$form->addFields($fields);
7277
}
78+
if(isset($wrapper))
79+
$added->wrap($wrapper[0],$wrapper[1]);
7380
}
7481
}
7582
}
@@ -127,6 +134,12 @@ public function addDividerBefore($index,$title){
127134
return $this;
128135
}
129136

137+
public function addWrapper($index,$contentBefore,$contentAfter=null){
138+
$index=$this->_getIndex($index);
139+
$this->_instanceViewer->addWrapper($index, $contentBefore,$contentAfter);
140+
return $this;
141+
}
142+
130143
public function run(JsUtils $js){
131144
return parent::run($js);
132145
}

Ajax/semantic/widgets/dataform/FormInstanceViewer.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
class FormInstanceViewer extends InstanceViewer {
1010
protected $separators;
1111
protected $headers;
12+
protected $wrappers;
1213

1314
public function __construct($identifier,$instance=NULL, $captions=NULL) {
1415
parent::__construct($identifier,$instance=NULL, $captions=NULL);
1516
$this->separators=[-1];
1617
$this->headers=[];
18+
$this->wrappers=[];
1719
$this->defaultValueFunction=function($name,$value,$index){
1820
$caption=$this->getCaption($index);
1921
$input=new HtmlFormInput($this->widgetIdentifier."-".$name,$caption,"text",$value);
@@ -59,6 +61,11 @@ public function addHeaderDividerBefore($fieldNum,$header){
5961
return $this;
6062
}
6163

64+
public function addWrapper($fieldNum,$contentBefore,$contentAfter=null){
65+
$this->wrappers[$fieldNum]=[$contentBefore,$contentAfter];
66+
return $this;
67+
}
68+
6269
public function getSeparators() {
6370
return $this->separators;
6471
}
@@ -88,5 +95,15 @@ public function getHeaders() {
8895
return $this->headers;
8996
}
9097

98+
public function getWrappers() {
99+
return $this->wrappers;
100+
}
101+
102+
public function setWrappers($wrappers) {
103+
$this->wrappers=$wrappers;
104+
return $this;
105+
}
106+
107+
91108

92109
}

0 commit comments

Comments
 (0)