Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Support for edge-cases

  • Loading branch information...
commit adc95d001d06ac0ebb15af5ba56020c5fa4f8d2c 1 parent 05dde3a
Kevin van Zonneveld authored March 29, 2012

Showing 1 changed file with 19 additions and 11 deletions. Show diff stats Hide diff stats

  1. 30  View/Helper/BootstrapFormHelper.php
30  View/Helper/BootstrapFormHelper.php
@@ -24,19 +24,27 @@ public function create($model = null, $options = array()) {
24 24
  * Add divs and classes necessary for bootstrap
25 25
  *
26 26
  */
27  
-	public function input($fieldName, $options = array()) {
  27
+	public function input($fieldName, $params = array()) {
28 28
 		$defaults = array(
29 29
 			'div' => array('class' => 'control-group'),
30 30
 			'label' => array('class' => 'control-label'),
31 31
 			'between' => '<div class="controls">',
32  
-			'after' => '</div>',
  32
+			// 'after' => '</div>',
33 33
 			'format' => array('before', 'label', 'between', 'input', 'error', 'after'),
34 34
 		);
35 35
 
36  
-		// Convenience params for bootstrap addons (http://twitter.github.com/bootstrap/base-css.html#forms)
  36
+		if (isset($params['div']) && $params['div'] === false) {
  37
+			unset($defaults['between'], $defaults['after']);
  38
+		}
  39
+
  40
+		$options = Set::merge($defaults, $params);
  41
+
37 42
 		$prepend = isset($options['bootstrap-prepend']) && is_string($options['bootstrap-prepend']) ? " input-prepend" : "";
38 43
 		$append  = isset($options['bootstrap-append'])  && is_string($options['bootstrap-append'])  ? " input-append"  : "";
39 44
 		if ($prepend || $append) {
  45
+			if (!isset($options['before'])) {
  46
+				$options['before'] = '';
  47
+			}
40 48
 			if (!isset($options['between'])) {
41 49
 				$options['between'] = '';
42 50
 			}
@@ -44,7 +52,7 @@ public function input($fieldName, $options = array()) {
44 52
 				$options['after'] = '';
45 53
 			}
46 54
 
47  
-			$options['between'] .= '<div class="' . $prepend . $append . '">';
  55
+			$options['before'] .= '<div class="' . trim($prepend . $append) . '">';
48 56
 
49 57
 			if ($prepend) {
50 58
 				$options['between'] .= '<span class="add-on">' . $options['bootstrap-prepend'] .  '</span>';
@@ -60,14 +68,10 @@ public function input($fieldName, $options = array()) {
60 68
 			unset($options['bootstrap-append']);
61 69
 		}
62 70
 
63  
-		if (isset($options['div']) && $options['div'] === false) {
64  
-			unset($defaults['between'], $defaults['after']);
65  
-		}
66  
-		if (isset($options['after']) && is_string($options['after'])) {
67  
-			$options['after'] .= '</div>';
  71
+		if (!isset($options['after'])) {
  72
+			$options['after'] = '';
68 73
 		}
69  
-
70  
-		$options = Set::merge($defaults, $options);
  74
+		$options['after'] .= '</div>';
71 75
 
72 76
 		if (isset($options['label']) && is_string($options['label'])) {
73 77
 			$options['label'] = array(
@@ -76,6 +80,10 @@ public function input($fieldName, $options = array()) {
76 80
 			);
77 81
 		}
78 82
 
  83
+		// if ($append) {
  84
+		// 	prd(compact('fieldName', 'options', 'params', 'default'));
  85
+		// }
  86
+
79 87
 		return parent::input($fieldName, $options);
80 88
 	}
81 89
 

0 notes on commit adc95d0

Please sign in to comment.
Something went wrong with that request. Please try again.