|
6 | 6 | use Collective\Html\HtmlBuilder;
|
7 | 7 | use Illuminate\Contracts\Config\Repository as Config;
|
8 | 8 | use Illuminate\Support\Facades\Lang;
|
| 9 | +use Illuminate\Support\HtmlString; |
9 | 10 | use Illuminate\Support\Str;
|
10 | 11 |
|
11 | 12 | class BootstrapForm
|
@@ -60,6 +61,13 @@ class BootstrapForm
|
60 | 61 | */
|
61 | 62 | protected $rightColumnClass;
|
62 | 63 |
|
| 64 | + /** |
| 65 | + * The errorbag that is used for validation (multiple forms) |
| 66 | + * |
| 67 | + * @var string |
| 68 | + */ |
| 69 | + protected $errorBag = 'default'; |
| 70 | + |
63 | 71 | /**
|
64 | 72 | * Suffix to add to the label string when a field is required
|
65 | 73 | *
|
@@ -142,6 +150,10 @@ public function open(array $options = [])
|
142 | 150 | return $this->model($options);
|
143 | 151 | }
|
144 | 152 |
|
| 153 | + if (array_key_exists('errorbag', $options)) { |
| 154 | + $this->setErrorBag($options['errorbag']); |
| 155 | + } |
| 156 | + |
145 | 157 | return $this->form->open($options);
|
146 | 158 | }
|
147 | 159 |
|
@@ -610,8 +622,17 @@ public function radios(
|
610 | 622 | public function label($name, $value = null, array $options = [])
|
611 | 623 | {
|
612 | 624 | $options = $this->getLabelOptions($options);
|
| 625 | + $escapeHtml = false; |
| 626 | + |
| 627 | + if (is_array($value) and isset($value['html'])) { |
| 628 | + $value = $value['html']; |
| 629 | + } elseif ($value instanceof HtmlString) { |
| 630 | + $value = $value->toHtml(); |
| 631 | + } else { |
| 632 | + $escapeHtml = true; |
| 633 | + } |
613 | 634 |
|
614 |
| - return $this->form->label($name, $value, $options); |
| 635 | + return $this->form->label($name, $value, $options, $escapeHtml); |
615 | 636 | }
|
616 | 637 |
|
617 | 638 |
|
@@ -766,11 +787,15 @@ public function select($name, $label = null, $list = [], $selected = null, array
|
766 | 787 | */
|
767 | 788 | protected function getLabelTitle($label, $name, $options)
|
768 | 789 | {
|
| 790 | + if ($label === false) { |
| 791 | + return null; |
| 792 | + } |
| 793 | + |
769 | 794 | if (is_null($label) && Lang::has("forms.{$name}")) {
|
770 | 795 | return Lang::get("forms.{$name}");
|
771 | 796 | }
|
772 | 797 |
|
773 |
| - $label = $label ?: Str::title($name); |
| 798 | + $label = $label ?: str_replace('_', ' ', Str::title($name)); |
774 | 799 |
|
775 | 800 | if (isset($options['required'])) {
|
776 | 801 | $label = sprintf('%s %s', $label, $this->getLabelRequiredMark());
|
@@ -1049,6 +1074,18 @@ public function setGroupRequiredClass($cssClass)
|
1049 | 1074 | }
|
1050 | 1075 |
|
1051 | 1076 |
|
| 1077 | + /** |
| 1078 | + * Set the errorBag used for validation |
| 1079 | + * |
| 1080 | + * @param $errorBag |
| 1081 | + * |
| 1082 | + * @return void |
| 1083 | + */ |
| 1084 | + protected function setErrorBag($errorBag) |
| 1085 | + { |
| 1086 | + $this->errorBag = $errorBag; |
| 1087 | + } |
| 1088 | + |
1052 | 1089 | /**
|
1053 | 1090 | * Flatten arrayed field names to work with the validator, including removing "[]",
|
1054 | 1091 | * and converting nested arrays like "foo[bar][baz]" to "foo.bar.baz".
|
@@ -1096,10 +1133,10 @@ protected function getFieldError($field, $format = '<span class="help-block">:me
|
1096 | 1133 | $allErrors = $this->config->get('bootstrap_form.show_all_errors');
|
1097 | 1134 |
|
1098 | 1135 | if ($allErrors) {
|
1099 |
| - return implode('', $this->getErrors()->get($field, $format)); |
| 1136 | + return implode('', $this->getErrors()->{$this->errorBag}->get($field, $format)); |
1100 | 1137 | }
|
1101 | 1138 |
|
1102 |
| - return $this->getErrors()->first($field, $format); |
| 1139 | + return $this->getErrors()->{$this->errorBag}->first($field, $format); |
1103 | 1140 | }
|
1104 | 1141 | }
|
1105 | 1142 |
|
|
0 commit comments