@@ -10,105 +10,105 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | class Button extends Field |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * The Button default element |
|
| 15 | - * |
|
| 16 | - * @var string |
|
| 17 | - */ |
|
| 18 | - protected $element = 'input'; |
|
| 13 | + /** |
|
| 14 | + * The Button default element |
|
| 15 | + * |
|
| 16 | + * @var string |
|
| 17 | + */ |
|
| 18 | + protected $element = 'input'; |
|
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * Default value for self-closing |
|
| 22 | - * |
|
| 23 | - * @var boolean |
|
| 24 | - */ |
|
| 25 | - protected $isSelfClosing = true; |
|
| 20 | + /** |
|
| 21 | + * Default value for self-closing |
|
| 22 | + * |
|
| 23 | + * @var boolean |
|
| 24 | + */ |
|
| 25 | + protected $isSelfClosing = true; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * A list of class properties to be added to attributes |
|
| 29 | - * |
|
| 30 | - * @var array |
|
| 31 | - */ |
|
| 32 | - protected $injectedProperties = array( |
|
| 33 | - 'name', |
|
| 34 | - 'type', |
|
| 35 | - 'value', |
|
| 36 | - ); |
|
| 27 | + /** |
|
| 28 | + * A list of class properties to be added to attributes |
|
| 29 | + * |
|
| 30 | + * @var array |
|
| 31 | + */ |
|
| 32 | + protected $injectedProperties = array( |
|
| 33 | + 'name', |
|
| 34 | + 'type', |
|
| 35 | + 'value', |
|
| 36 | + ); |
|
| 37 | 37 | |
| 38 | - //////////////////////////////////////////////////////////////////// |
|
| 39 | - /////////////////////////// CORE METHODS /////////////////////////// |
|
| 40 | - //////////////////////////////////////////////////////////////////// |
|
| 38 | + //////////////////////////////////////////////////////////////////// |
|
| 39 | + /////////////////////////// CORE METHODS /////////////////////////// |
|
| 40 | + //////////////////////////////////////////////////////////////////// |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Easier arguments order for button fields |
|
| 44 | - * |
|
| 45 | - * @param Container $app The Container |
|
| 46 | - * @param string $type button/submit/reset/etc |
|
| 47 | - * @param string $value The text of the button |
|
| 48 | - * @param string $link Its link |
|
| 49 | - * @param array $attributes Its attributes |
|
| 50 | - */ |
|
| 51 | - public function __construct(Container $app, $type, $value, $link, $attributes) |
|
| 52 | - { |
|
| 53 | - $this->app = $app; |
|
| 54 | - $this->attributes = (array) $attributes; |
|
| 55 | - $this->type = $type; |
|
| 56 | - $this->value($value); |
|
| 42 | + /** |
|
| 43 | + * Easier arguments order for button fields |
|
| 44 | + * |
|
| 45 | + * @param Container $app The Container |
|
| 46 | + * @param string $type button/submit/reset/etc |
|
| 47 | + * @param string $value The text of the button |
|
| 48 | + * @param string $link Its link |
|
| 49 | + * @param array $attributes Its attributes |
|
| 50 | + */ |
|
| 51 | + public function __construct(Container $app, $type, $value, $link, $attributes) |
|
| 52 | + { |
|
| 53 | + $this->app = $app; |
|
| 54 | + $this->attributes = (array) $attributes; |
|
| 55 | + $this->type = $type; |
|
| 56 | + $this->value($value); |
|
| 57 | 57 | |
| 58 | - // Set correct element for the various button patterns |
|
| 59 | - switch ($type) { |
|
| 60 | - case 'button': |
|
| 61 | - $this->element = 'button'; |
|
| 62 | - $this->isSelfClosing = false; |
|
| 63 | - break; |
|
| 64 | - case 'link': |
|
| 65 | - $this->type = null; |
|
| 66 | - $this->element = 'a'; |
|
| 67 | - $this->attributes['href'] = $link; |
|
| 68 | - $this->isSelfClosing = false; |
|
| 69 | - break; |
|
| 70 | - } |
|
| 71 | - } |
|
| 58 | + // Set correct element for the various button patterns |
|
| 59 | + switch ($type) { |
|
| 60 | + case 'button': |
|
| 61 | + $this->element = 'button'; |
|
| 62 | + $this->isSelfClosing = false; |
|
| 63 | + break; |
|
| 64 | + case 'link': |
|
| 65 | + $this->type = null; |
|
| 66 | + $this->element = 'a'; |
|
| 67 | + $this->attributes['href'] = $link; |
|
| 68 | + $this->isSelfClosing = false; |
|
| 69 | + break; |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - //////////////////////////////////////////////////////////////////// |
|
| 74 | - ////////////////////////// FIELD METHODS /////////////////////////// |
|
| 75 | - //////////////////////////////////////////////////////////////////// |
|
| 73 | + //////////////////////////////////////////////////////////////////// |
|
| 74 | + ////////////////////////// FIELD METHODS /////////////////////////// |
|
| 75 | + //////////////////////////////////////////////////////////////////// |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * Check if the field is a button |
|
| 79 | - * |
|
| 80 | - * @return boolean |
|
| 81 | - */ |
|
| 82 | - public function isButton() |
|
| 83 | - { |
|
| 84 | - return true; |
|
| 85 | - } |
|
| 77 | + /** |
|
| 78 | + * Check if the field is a button |
|
| 79 | + * |
|
| 80 | + * @return boolean |
|
| 81 | + */ |
|
| 82 | + public function isButton() |
|
| 83 | + { |
|
| 84 | + return true; |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * Prepend an icon to the button |
|
| 89 | - * |
|
| 90 | - * @param string $icon |
|
| 91 | - * @param array $attributes |
|
| 92 | - * |
|
| 93 | - * @return self |
|
| 94 | - */ |
|
| 95 | - public function icon($icon, $attributes = array()) |
|
| 96 | - { |
|
| 97 | - $icon = $this->app['former.framework']->createIcon($icon, $attributes); |
|
| 98 | - $this->value = $icon.' '.$this->value; |
|
| 87 | + /** |
|
| 88 | + * Prepend an icon to the button |
|
| 89 | + * |
|
| 90 | + * @param string $icon |
|
| 91 | + * @param array $attributes |
|
| 92 | + * |
|
| 93 | + * @return self |
|
| 94 | + */ |
|
| 95 | + public function icon($icon, $attributes = array()) |
|
| 96 | + { |
|
| 97 | + $icon = $this->app['former.framework']->createIcon($icon, $attributes); |
|
| 98 | + $this->value = $icon.' '.$this->value; |
|
| 99 | 99 | |
| 100 | - return $this; |
|
| 101 | - } |
|
| 100 | + return $this; |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - /** |
|
| 104 | - * Hijack Former's Object model value method |
|
| 105 | - * |
|
| 106 | - * @param string $value The new button text |
|
| 107 | - */ |
|
| 108 | - public function value($value) |
|
| 109 | - { |
|
| 110 | - $this->value = Helpers::translate($value); |
|
| 103 | + /** |
|
| 104 | + * Hijack Former's Object model value method |
|
| 105 | + * |
|
| 106 | + * @param string $value The new button text |
|
| 107 | + */ |
|
| 108 | + public function value($value) |
|
| 109 | + { |
|
| 110 | + $this->value = Helpers::translate($value); |
|
| 111 | 111 | |
| 112 | - return $this; |
|
| 113 | - } |
|
| 112 | + return $this; |
|
| 113 | + } |
|
| 114 | 114 | } |
@@ -8,28 +8,28 @@ |
||
| 8 | 8 | */ |
| 9 | 9 | class Checkbox extends Checkable |
| 10 | 10 | { |
| 11 | - /** |
|
| 12 | - * The current checkable type |
|
| 13 | - * |
|
| 14 | - * @var string |
|
| 15 | - */ |
|
| 16 | - protected $checkable = 'checkbox'; |
|
| 11 | + /** |
|
| 12 | + * The current checkable type |
|
| 13 | + * |
|
| 14 | + * @var string |
|
| 15 | + */ |
|
| 16 | + protected $checkable = 'checkbox'; |
|
| 17 | 17 | |
| 18 | - //////////////////////////////////////////////////////////////////// |
|
| 19 | - ////////////////////////// FIELD METHODS /////////////////////////// |
|
| 20 | - //////////////////////////////////////////////////////////////////// |
|
| 18 | + //////////////////////////////////////////////////////////////////// |
|
| 19 | + ////////////////////////// FIELD METHODS /////////////////////////// |
|
| 20 | + //////////////////////////////////////////////////////////////////// |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Create a serie of checkboxes |
|
| 24 | - */ |
|
| 25 | - public function checkboxes() |
|
| 26 | - { |
|
| 27 | - if ($this->isGrouped()) { |
|
| 28 | - // Remove any possible items added by the Populator. |
|
| 29 | - $this->items = array(); |
|
| 30 | - } |
|
| 31 | - $this->items(func_get_args()); |
|
| 22 | + /** |
|
| 23 | + * Create a serie of checkboxes |
|
| 24 | + */ |
|
| 25 | + public function checkboxes() |
|
| 26 | + { |
|
| 27 | + if ($this->isGrouped()) { |
|
| 28 | + // Remove any possible items added by the Populator. |
|
| 29 | + $this->items = array(); |
|
| 30 | + } |
|
| 31 | + $this->items(func_get_args()); |
|
| 32 | 32 | |
| 33 | - return $this; |
|
| 34 | - } |
|
| 33 | + return $this; |
|
| 34 | + } |
|
| 35 | 35 | } |
@@ -8,24 +8,24 @@ |
||
| 8 | 8 | */ |
| 9 | 9 | class Radio extends Checkable |
| 10 | 10 | { |
| 11 | - /** |
|
| 12 | - * The current checkable type |
|
| 13 | - * |
|
| 14 | - * @var string |
|
| 15 | - */ |
|
| 16 | - protected $checkable = 'radio'; |
|
| 11 | + /** |
|
| 12 | + * The current checkable type |
|
| 13 | + * |
|
| 14 | + * @var string |
|
| 15 | + */ |
|
| 16 | + protected $checkable = 'radio'; |
|
| 17 | 17 | |
| 18 | - //////////////////////////////////////////////////////////////////// |
|
| 19 | - ////////////////////////// FIELD METHODS /////////////////////////// |
|
| 20 | - //////////////////////////////////////////////////////////////////// |
|
| 18 | + //////////////////////////////////////////////////////////////////// |
|
| 19 | + ////////////////////////// FIELD METHODS /////////////////////////// |
|
| 20 | + //////////////////////////////////////////////////////////////////// |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Create a serie of radios |
|
| 24 | - */ |
|
| 25 | - public function radios() |
|
| 26 | - { |
|
| 27 | - $this->items(func_get_args()); |
|
| 22 | + /** |
|
| 23 | + * Create a serie of radios |
|
| 24 | + */ |
|
| 25 | + public function radios() |
|
| 26 | + { |
|
| 27 | + $this->items(func_get_args()); |
|
| 28 | 28 | |
| 29 | - return $this; |
|
| 30 | - } |
|
| 29 | + return $this; |
|
| 30 | + } |
|
| 31 | 31 | } |
@@ -8,20 +8,20 @@ |
||
| 8 | 8 | */ |
| 9 | 9 | class Plaintext extends Field |
| 10 | 10 | { |
| 11 | - //////////////////////////////////////////////////////////////////// |
|
| 12 | - /////////////////////////// CORE METHODS /////////////////////////// |
|
| 13 | - //////////////////////////////////////////////////////////////////// |
|
| 11 | + //////////////////////////////////////////////////////////////////// |
|
| 12 | + /////////////////////////// CORE METHODS /////////////////////////// |
|
| 13 | + //////////////////////////////////////////////////////////////////// |
|
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Prints out the current tag |
|
| 17 | - * |
|
| 18 | - * @return string A plain text tag |
|
| 19 | - */ |
|
| 20 | - public function render() |
|
| 21 | - { |
|
| 22 | - $this->addClass($this->app['former.framework']->getPlainTextClasses()); |
|
| 23 | - $this->setId(); |
|
| 15 | + /** |
|
| 16 | + * Prints out the current tag |
|
| 17 | + * |
|
| 18 | + * @return string A plain text tag |
|
| 19 | + */ |
|
| 20 | + public function render() |
|
| 21 | + { |
|
| 22 | + $this->addClass($this->app['former.framework']->getPlainTextClasses()); |
|
| 23 | + $this->setId(); |
|
| 24 | 24 | |
| 25 | - return $this->app['former.framework']->createPlainTextField($this); |
|
| 26 | - } |
|
| 25 | + return $this->app['former.framework']->createPlainTextField($this); |
|
| 26 | + } |
|
| 27 | 27 | } |
@@ -12,31 +12,31 @@ |
||
| 12 | 12 | class Hidden extends Field |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - //////////////////////////////////////////////////////////////////// |
|
| 16 | - /////////////////////////// CORE METHODS /////////////////////////// |
|
| 17 | - //////////////////////////////////////////////////////////////////// |
|
| 15 | + //////////////////////////////////////////////////////////////////// |
|
| 16 | + /////////////////////////// CORE METHODS /////////////////////////// |
|
| 17 | + //////////////////////////////////////////////////////////////////// |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * Easier arguments order for hidden fields |
|
| 21 | - * |
|
| 22 | - * @param Container $app The Container |
|
| 23 | - * @param string $type hidden |
|
| 24 | - * @param string $name Field names |
|
| 25 | - * @param string $value Its value |
|
| 26 | - * @param array $attributes Attributes |
|
| 27 | - */ |
|
| 28 | - public function __construct(Container $app, $type, $name, $value, $attributes) |
|
| 29 | - { |
|
| 30 | - parent::__construct($app, $type, $name, '', $value, $attributes); |
|
| 31 | - } |
|
| 19 | + /** |
|
| 20 | + * Easier arguments order for hidden fields |
|
| 21 | + * |
|
| 22 | + * @param Container $app The Container |
|
| 23 | + * @param string $type hidden |
|
| 24 | + * @param string $name Field names |
|
| 25 | + * @param string $value Its value |
|
| 26 | + * @param array $attributes Attributes |
|
| 27 | + */ |
|
| 28 | + public function __construct(Container $app, $type, $name, $value, $attributes) |
|
| 29 | + { |
|
| 30 | + parent::__construct($app, $type, $name, '', $value, $attributes); |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Outputs a hidden field |
|
| 35 | - * |
|
| 36 | - * @return string An <input type="hidden" /> |
|
| 37 | - */ |
|
| 38 | - public function render() |
|
| 39 | - { |
|
| 40 | - return HtmlInput::create('hidden', $this->name, Helpers::encode($this->value), $this->attributes)->render(); |
|
| 41 | - } |
|
| 33 | + /** |
|
| 34 | + * Outputs a hidden field |
|
| 35 | + * |
|
| 36 | + * @return string An <input type="hidden" /> |
|
| 37 | + */ |
|
| 38 | + public function render() |
|
| 39 | + { |
|
| 40 | + return HtmlInput::create('hidden', $this->name, Helpers::encode($this->value), $this->attributes)->render(); |
|
| 41 | + } |
|
| 42 | 42 | } |
@@ -10,146 +10,146 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | class Input extends Field |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * Current datalist stored |
|
| 15 | - * |
|
| 16 | - * @var array |
|
| 17 | - */ |
|
| 18 | - protected $datalist = array(); |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * Properties to be injected as attributes |
|
| 22 | - * |
|
| 23 | - * @var array |
|
| 24 | - */ |
|
| 25 | - protected $injectedProperties = array('type', 'name', 'value'); |
|
| 26 | - |
|
| 27 | - //////////////////////////////////////////////////////////////////// |
|
| 28 | - /////////////////////////// CORE METHODS /////////////////////////// |
|
| 29 | - //////////////////////////////////////////////////////////////////// |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * Build an input field |
|
| 33 | - * |
|
| 34 | - * @param Container $app The Container |
|
| 35 | - * @param string $type The input type |
|
| 36 | - * @param string $name Field name |
|
| 37 | - * @param string $label Its label |
|
| 38 | - * @param string $value Its value |
|
| 39 | - * @param array $attributes Attributes |
|
| 40 | - */ |
|
| 41 | - public function __construct(Container $app, $type, $name, $label, $value, $attributes) |
|
| 42 | - { |
|
| 43 | - parent::__construct($app, $type, $name, $label, $value, $attributes); |
|
| 44 | - |
|
| 45 | - // Multiple models population |
|
| 46 | - if (is_array($this->value)) { |
|
| 47 | - $values = array(); |
|
| 48 | - foreach ($this->value as $value) { |
|
| 49 | - $values[] = is_object($value) ? $value->__toString() : $value; |
|
| 50 | - } |
|
| 51 | - if (isset($values)) { |
|
| 52 | - $this->value = implode(', ', $values); |
|
| 53 | - } |
|
| 54 | - } |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Prints out the current tag |
|
| 59 | - * |
|
| 60 | - * @return string An input tag |
|
| 61 | - */ |
|
| 62 | - public function render() |
|
| 63 | - { |
|
| 64 | - // Particular case of the search element |
|
| 65 | - if ($this->isOfType('search')) { |
|
| 66 | - $this->asSearch(); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - $this->setId(); |
|
| 70 | - |
|
| 71 | - // Render main input |
|
| 72 | - $input = parent::render(); |
|
| 73 | - |
|
| 74 | - // If we have a datalist to append, print it out |
|
| 75 | - if ($this->datalist) { |
|
| 76 | - $input .= $this->createDatalist($this->list, $this->datalist); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - return $input; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - //////////////////////////////////////////////////////////////////// |
|
| 83 | - ////////////////////////// FIELD METHODS /////////////////////////// |
|
| 84 | - //////////////////////////////////////////////////////////////////// |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Adds a datalist to the current field |
|
| 88 | - * |
|
| 89 | - * @param array $datalist An array to use a source |
|
| 90 | - * @param string $value The field to use as value |
|
| 91 | - * @param string $key The field to use as key |
|
| 92 | - */ |
|
| 93 | - public function useDatalist($datalist, $value = null, $key = null) |
|
| 94 | - { |
|
| 95 | - $datalist = Helpers::queryToArray($datalist, $value, $key); |
|
| 96 | - |
|
| 97 | - $list = $this->list ?: 'datalist_'.$this->name; |
|
| 98 | - |
|
| 99 | - // Create the link to the datalist |
|
| 100 | - $this->list = $list; |
|
| 101 | - $this->datalist = $datalist; |
|
| 102 | - |
|
| 103 | - return $this; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Add range to the input |
|
| 108 | - * |
|
| 109 | - * @param integer $min |
|
| 110 | - * @param integer $max |
|
| 111 | - * |
|
| 112 | - * @return self |
|
| 113 | - */ |
|
| 114 | - public function range($min, $max) |
|
| 115 | - { |
|
| 116 | - $this->min($min); |
|
| 117 | - $this->max($max); |
|
| 118 | - |
|
| 119 | - return $this; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - //////////////////////////////////////////////////////////////////// |
|
| 123 | - /////////////////////////////// HELPERS //////////////////////////// |
|
| 124 | - //////////////////////////////////////////////////////////////////// |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Render a text element as a search element |
|
| 128 | - */ |
|
| 129 | - private function asSearch() |
|
| 130 | - { |
|
| 131 | - $this->type = 'text'; |
|
| 132 | - $this->addClass('search-query'); |
|
| 133 | - |
|
| 134 | - return $this; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * Renders a datalist |
|
| 139 | - * |
|
| 140 | - * @param string $id The datalist's id attribute |
|
| 141 | - * @param array $values Its values |
|
| 142 | - * |
|
| 143 | - * @return string A <datalist> tag |
|
| 144 | - */ |
|
| 145 | - private function createDatalist($id, $values) |
|
| 146 | - { |
|
| 147 | - $datalist = '<datalist id="'.$id.'">'; |
|
| 148 | - foreach ($values as $key => $value) { |
|
| 149 | - $datalist .= '<option value="'.$value.'">'.$key.'</option>'; |
|
| 150 | - } |
|
| 151 | - $datalist .= '</datalist>'; |
|
| 152 | - |
|
| 153 | - return $datalist; |
|
| 154 | - } |
|
| 13 | + /** |
|
| 14 | + * Current datalist stored |
|
| 15 | + * |
|
| 16 | + * @var array |
|
| 17 | + */ |
|
| 18 | + protected $datalist = array(); |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * Properties to be injected as attributes |
|
| 22 | + * |
|
| 23 | + * @var array |
|
| 24 | + */ |
|
| 25 | + protected $injectedProperties = array('type', 'name', 'value'); |
|
| 26 | + |
|
| 27 | + //////////////////////////////////////////////////////////////////// |
|
| 28 | + /////////////////////////// CORE METHODS /////////////////////////// |
|
| 29 | + //////////////////////////////////////////////////////////////////// |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * Build an input field |
|
| 33 | + * |
|
| 34 | + * @param Container $app The Container |
|
| 35 | + * @param string $type The input type |
|
| 36 | + * @param string $name Field name |
|
| 37 | + * @param string $label Its label |
|
| 38 | + * @param string $value Its value |
|
| 39 | + * @param array $attributes Attributes |
|
| 40 | + */ |
|
| 41 | + public function __construct(Container $app, $type, $name, $label, $value, $attributes) |
|
| 42 | + { |
|
| 43 | + parent::__construct($app, $type, $name, $label, $value, $attributes); |
|
| 44 | + |
|
| 45 | + // Multiple models population |
|
| 46 | + if (is_array($this->value)) { |
|
| 47 | + $values = array(); |
|
| 48 | + foreach ($this->value as $value) { |
|
| 49 | + $values[] = is_object($value) ? $value->__toString() : $value; |
|
| 50 | + } |
|
| 51 | + if (isset($values)) { |
|
| 52 | + $this->value = implode(', ', $values); |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Prints out the current tag |
|
| 59 | + * |
|
| 60 | + * @return string An input tag |
|
| 61 | + */ |
|
| 62 | + public function render() |
|
| 63 | + { |
|
| 64 | + // Particular case of the search element |
|
| 65 | + if ($this->isOfType('search')) { |
|
| 66 | + $this->asSearch(); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + $this->setId(); |
|
| 70 | + |
|
| 71 | + // Render main input |
|
| 72 | + $input = parent::render(); |
|
| 73 | + |
|
| 74 | + // If we have a datalist to append, print it out |
|
| 75 | + if ($this->datalist) { |
|
| 76 | + $input .= $this->createDatalist($this->list, $this->datalist); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + return $input; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + //////////////////////////////////////////////////////////////////// |
|
| 83 | + ////////////////////////// FIELD METHODS /////////////////////////// |
|
| 84 | + //////////////////////////////////////////////////////////////////// |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Adds a datalist to the current field |
|
| 88 | + * |
|
| 89 | + * @param array $datalist An array to use a source |
|
| 90 | + * @param string $value The field to use as value |
|
| 91 | + * @param string $key The field to use as key |
|
| 92 | + */ |
|
| 93 | + public function useDatalist($datalist, $value = null, $key = null) |
|
| 94 | + { |
|
| 95 | + $datalist = Helpers::queryToArray($datalist, $value, $key); |
|
| 96 | + |
|
| 97 | + $list = $this->list ?: 'datalist_'.$this->name; |
|
| 98 | + |
|
| 99 | + // Create the link to the datalist |
|
| 100 | + $this->list = $list; |
|
| 101 | + $this->datalist = $datalist; |
|
| 102 | + |
|
| 103 | + return $this; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Add range to the input |
|
| 108 | + * |
|
| 109 | + * @param integer $min |
|
| 110 | + * @param integer $max |
|
| 111 | + * |
|
| 112 | + * @return self |
|
| 113 | + */ |
|
| 114 | + public function range($min, $max) |
|
| 115 | + { |
|
| 116 | + $this->min($min); |
|
| 117 | + $this->max($max); |
|
| 118 | + |
|
| 119 | + return $this; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + //////////////////////////////////////////////////////////////////// |
|
| 123 | + /////////////////////////////// HELPERS //////////////////////////// |
|
| 124 | + //////////////////////////////////////////////////////////////////// |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Render a text element as a search element |
|
| 128 | + */ |
|
| 129 | + private function asSearch() |
|
| 130 | + { |
|
| 131 | + $this->type = 'text'; |
|
| 132 | + $this->addClass('search-query'); |
|
| 133 | + |
|
| 134 | + return $this; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * Renders a datalist |
|
| 139 | + * |
|
| 140 | + * @param string $id The datalist's id attribute |
|
| 141 | + * @param array $values Its values |
|
| 142 | + * |
|
| 143 | + * @return string A <datalist> tag |
|
| 144 | + */ |
|
| 145 | + private function createDatalist($id, $values) |
|
| 146 | + { |
|
| 147 | + $datalist = '<datalist id="'.$id.'">'; |
|
| 148 | + foreach ($values as $key => $value) { |
|
| 149 | + $datalist .= '<option value="'.$value.'">'.$key.'</option>'; |
|
| 150 | + } |
|
| 151 | + $datalist .= '</datalist>'; |
|
| 152 | + |
|
| 153 | + return $datalist; |
|
| 154 | + } |
|
| 155 | 155 | } |
@@ -9,21 +9,21 @@ |
||
| 9 | 9 | class Uneditable extends Field |
| 10 | 10 | { |
| 11 | 11 | |
| 12 | - //////////////////////////////////////////////////////////////////// |
|
| 13 | - /////////////////////////// CORE METHODS /////////////////////////// |
|
| 14 | - //////////////////////////////////////////////////////////////////// |
|
| 12 | + //////////////////////////////////////////////////////////////////// |
|
| 13 | + /////////////////////////// CORE METHODS /////////////////////////// |
|
| 14 | + //////////////////////////////////////////////////////////////////// |
|
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Prints out the current tag |
|
| 18 | - * |
|
| 19 | - * @return string An uneditable input tag |
|
| 20 | - */ |
|
| 21 | - public function render() |
|
| 22 | - { |
|
| 23 | - $this->addClass($this->app['former.framework']->getUneditableClasses()); |
|
| 16 | + /** |
|
| 17 | + * Prints out the current tag |
|
| 18 | + * |
|
| 19 | + * @return string An uneditable input tag |
|
| 20 | + */ |
|
| 21 | + public function render() |
|
| 22 | + { |
|
| 23 | + $this->addClass($this->app['former.framework']->getUneditableClasses()); |
|
| 24 | 24 | |
| 25 | - $this->setId(); |
|
| 25 | + $this->setId(); |
|
| 26 | 26 | |
| 27 | - return $this->app['former.framework']->createDisabledField($this); |
|
| 28 | - } |
|
| 27 | + return $this->app['former.framework']->createDisabledField($this); |
|
| 28 | + } |
|
| 29 | 29 | } |
@@ -8,17 +8,17 @@ |
||
| 8 | 8 | */ |
| 9 | 9 | class Textarea extends Field |
| 10 | 10 | { |
| 11 | - /** |
|
| 12 | - * The textarea's element |
|
| 13 | - * |
|
| 14 | - * @var string |
|
| 15 | - */ |
|
| 16 | - protected $element = 'textarea'; |
|
| 11 | + /** |
|
| 12 | + * The textarea's element |
|
| 13 | + * |
|
| 14 | + * @var string |
|
| 15 | + */ |
|
| 16 | + protected $element = 'textarea'; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * The textarea's self-closing state |
|
| 20 | - * |
|
| 21 | - * @var boolean |
|
| 22 | - */ |
|
| 23 | - protected $isSelfClosing = false; |
|
| 18 | + /** |
|
| 19 | + * The textarea's self-closing state |
|
| 20 | + * |
|
| 21 | + * @var boolean |
|
| 22 | + */ |
|
| 23 | + protected $isSelfClosing = false; |
|
| 24 | 24 | } |
@@ -9,17 +9,17 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | class Former extends Facade |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * Get the registered component. |
|
| 14 | - * |
|
| 15 | - * @return string |
|
| 16 | - */ |
|
| 17 | - protected static function getFacadeAccessor() |
|
| 18 | - { |
|
| 19 | - if (!static::$app) { |
|
| 20 | - static::$app = FormerServiceProvider::make(); |
|
| 21 | - } |
|
| 12 | + /** |
|
| 13 | + * Get the registered component. |
|
| 14 | + * |
|
| 15 | + * @return string |
|
| 16 | + */ |
|
| 17 | + protected static function getFacadeAccessor() |
|
| 18 | + { |
|
| 19 | + if (!static::$app) { |
|
| 20 | + static::$app = FormerServiceProvider::make(); |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - return 'former'; |
|
| 24 | - } |
|
| 23 | + return 'former'; |
|
| 24 | + } |
|
| 25 | 25 | } |