Skip to content
This repository was archived by the owner on Aug 30, 2020. It is now read-only.

Commit f535ba7

Browse files
committed
using custom error bag
1 parent 248fcab commit f535ba7

26 files changed

+131
-77
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,17 @@ return [
220220
...
221221
];
222222
```
223+
224+
<a name="errorBug"></a>
225+
# # Using Custom Error Message Bag
226+
> You can using custom error bag to display validation errors without any conflict.
227+
```
228+
// Default error bag
229+
BsForm::errorBag('default')
230+
231+
// Other error bag
232+
BsForm::errorBag('create')
233+
```
223234
<a name="example"></a>
224235
# # Example Register Form
225236
```

src/BsForm.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ class BsForm
7272
*/
7373
protected static $instance;
7474

75+
/**
76+
* The key to be used for the view error bag.
77+
*
78+
* @var string
79+
*/
80+
protected $errorBag = 'default';
81+
7582
/**
7683
* BsForm constructor.
7784
*/
@@ -97,7 +104,8 @@ public function registerComponent($name, $component)
97104
public function __call($name, $arguments)
98105
{
99106
if (isset($this->components[$name])) {
100-
$instance = new $this->components[$name]($this->resource);
107+
$instance = (new $this->components[$name]($this->resource))
108+
->errorBag($this->errorBag);
101109

102110
if ($instance instanceof LocalizableComponent) {
103111
$instance->locale($this->locale);
@@ -147,6 +155,19 @@ public function resource($resource)
147155
return $this;
148156
}
149157

158+
/**
159+
* The key to be used for the view error bag.
160+
*
161+
* @param string $bag
162+
* @return $this
163+
*/
164+
public function errorBag($bag = 'default')
165+
{
166+
$this->errorBag = $bag;
167+
168+
return $this;
169+
}
170+
150171
/**
151172
* Set the components style.
152173
*
@@ -175,7 +196,7 @@ public function clearStyle()
175196
/**
176197
* Set the input inline validation errors option.
177198
*
178-
* @param bool $bool
199+
* @param bool $bool
179200
* @return $this
180201
*/
181202
public function inlineValidation($bool = true)
@@ -227,4 +248,4 @@ private function __clone()
227248
{
228249
//
229250
}
230-
}
251+
}

src/Components/BaseComponent.php

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ abstract class BaseComponent implements Htmlable
9191
*/
9292
protected $inlineValidation = true;
9393

94+
/**
95+
* The key to be used for the view error bag.
96+
*
97+
* @var string
98+
*/
99+
protected $errorBag = 'default';
100+
94101
/**
95102
* Set resource name property.
96103
*
@@ -104,8 +111,8 @@ public function __construct($resource)
104111
/**
105112
* Initialized the input arguments.
106113
*
107-
* @param null $name
108-
* @param null $value
114+
* @param null $name
115+
* @param null $value
109116
* @return $this
110117
*/
111118
abstract public function init();
@@ -166,6 +173,19 @@ public function name($name)
166173
return $this;
167174
}
168175

176+
/**
177+
* The key to be used for the view error bag.
178+
*
179+
* @param string $bag
180+
* @return $this
181+
*/
182+
public function errorBag($bag = 'default')
183+
{
184+
$this->errorBag = $bag;
185+
186+
return $this;
187+
}
188+
169189
/**
170190
* @param $label
171191
* @return $this
@@ -225,8 +245,8 @@ public function autofocus($autofocus = true)
225245
/**
226246
* Add custom attribute.
227247
*
228-
* @param string|array $key
229-
* @param null $value
248+
* @param string|array $key
249+
* @param null $value
230250
* @return $this
231251
*/
232252
public function attribute($key, $value = null)
@@ -272,7 +292,7 @@ public function style($style)
272292
/**
273293
* Set the input inline validation errors option.
274294
*
275-
* @param bool $bool
295+
* @param bool $bool
276296
* @return $this
277297
*/
278298
public function inlineValidation($bool = true)
@@ -297,6 +317,7 @@ protected function render()
297317
'note' => $this->note,
298318
'attributes' => $this->attributes,
299319
'inlineValidation' => $this->inlineValidation,
320+
'errorBag' => $this->errorBag,
300321
], $this->viewComposer());
301322

302323
return view($this->getViewPath())
@@ -317,7 +338,7 @@ protected function viewComposer()
317338
/**
318339
* Transform the properties to be used in view.
319340
*
320-
* @param array $properties
341+
* @param array $properties
321342
* @return array
322343
*/
323344
protected function transformProperties(array $properties)
@@ -334,4 +355,4 @@ public function toHtml()
334355
{
335356
return $this->render();
336357
}
337-
}
358+
}

src/Facades/BsForm.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
* @method static \Elnooronline\LaravelBootstrapForms\BsForm style($style = null)
2424
* @method static \Elnooronline\LaravelBootstrapForms\BsForm clearStyle()
2525
* @method static \Elnooronline\LaravelBootstrapForms\BsForm inlineValidation($bool = true)
26+
* @method static \Elnooronline\LaravelBootstrapForms\BsForm errorBag($bag = 'default')
2627
* @method static \Illuminate\Support\HtmlString close()
2728
*
2829
* @package Elnooronline\LaravelBootstrapForms\Facades
@@ -38,4 +39,4 @@ protected static function getFacadeAccessor()
3839
{
3940
return 'bootstrap.form';
4041
}
41-
}
42+
}

src/views/checkbox/default.blade.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
<div class="form-group{{ $errors->has($nameWithoutBrackets) ? ' has-error' : '' }}">
1+
<div class="form-group{{ $errors->{$errorBag}->has($nameWithoutBrackets) ? ' has-error' : '' }}">
22
<div class="checkbox">
33
<label>
44
{{ Form::checkbox($name, $value, $checked) }} {{ $label }}
55
</label>
66
</div>
77
@if($inlineValidation)
8-
@if($errors->has($nameWithoutBrackets))
9-
<strong class="help-block">{{ $errors->first($nameWithoutBrackets) }}</strong>
8+
@if($errors->{$errorBag}->has($nameWithoutBrackets))
9+
<strong class="help-block">{{ $errors->{$errorBag}->first($nameWithoutBrackets) }}</strong>
1010
@else
1111
<strong class="help-block">{{ $note }}</strong>
1212
@endif

src/views/checkbox/vertical.blade.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
<div class="form-group{{ $errors->has($nameWithoutBrackets) ? ' has-error' : '' }}">
1+
<div class="form-group{{ $errors->{$errorBag}->has($nameWithoutBrackets) ? ' has-error' : '' }}">
22
<div class="col-sm-offset-2 col-sm-10">
33
<div class="checkbox">
44
<label>
55
{{ Form::checkbox($name, $value, $checked) }} {{ $label }}
66
</label>
77
</div>
88
@if($inlineValidation)
9-
@if($errors->has($nameWithoutBrackets))
10-
<strong class="help-block">{{ $errors->first($nameWithoutBrackets) }}</strong>
9+
@if($errors->{$errorBag}->has($nameWithoutBrackets))
10+
<strong class="help-block">{{ $errors->{$errorBag}->first($nameWithoutBrackets) }}</strong>
1111
@else
1212
<strong class="help-block">{{ $note }}</strong>
1313
@endif

src/views/date/default.blade.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
<div class="form-group{{ $errors->has($nameWithoutBrackets) ? ' has-error' : '' }}">
1+
<div class="form-group{{ $errors->{$errorBag}->has($nameWithoutBrackets) ? ' has-error' : '' }}">
22
@if($label)
33
{{ Form::label($name, $label, ['class' => 'content-label']) }}
44
@endif
55

66
{{ Form::date($name, $value, array_merge(['class' => 'form-control'], $attributes)) }}
77

88
@if($inlineValidation)
9-
@if($errors->has($nameWithoutBrackets))
10-
<strong class="help-block">{{ $errors->first($nameWithoutBrackets) }}</strong>
9+
@if($errors->{$errorBag}->has($nameWithoutBrackets))
10+
<strong class="help-block">{{ $errors->{$errorBag}->first($nameWithoutBrackets) }}</strong>
1111
@else
1212
<strong class="help-block">{{ $note }}</strong>
1313
@endif

src/views/date/vertical.blade.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="form-group{{ $errors->has($nameWithoutBrackets) ? ' has-error' : '' }}">
1+
<div class="form-group{{ $errors->{$errorBag}->has($nameWithoutBrackets) ? ' has-error' : '' }}">
22
<div class="row">
33
@if($label)
44
{{ Form::label($name, $label, ['class' => 'content-label col-md-2']) }}
@@ -11,8 +11,8 @@
1111
{{ Form::date($name, $value, array_merge(['class' => 'form-control'], $attributes)) }}
1212

1313
@if($inlineValidation)
14-
@if($errors->has($nameWithoutBrackets))
15-
<strong class="help-block">{{ $errors->first($nameWithoutBrackets) }}</strong>
14+
@if($errors->{$errorBag}->has($nameWithoutBrackets))
15+
<strong class="help-block">{{ $errors->{$errorBag}->first($nameWithoutBrackets) }}</strong>
1616
@else
1717
<strong class="help-block">{{ $note }}</strong>
1818
@endif

src/views/email/default.blade.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
<div class="form-group{{ $errors->has($nameWithoutBrackets) ? ' has-error' : '' }}">
1+
<div class="form-group{{ $errors->{$errorBag}->has($nameWithoutBrackets) ? ' has-error' : '' }}">
22
@if($label)
33
{{ Form::label($name, $label, ['class' => 'content-label']) }}
44
@endif
55

66
{{ Form::email($name, $value, array_merge(['class' => 'form-control'], $attributes)) }}
77

88
@if($inlineValidation)
9-
@if($errors->has($nameWithoutBrackets))
10-
<strong class="help-block">{{ $errors->first($nameWithoutBrackets) }}</strong>
9+
@if($errors->{$errorBag}->has($nameWithoutBrackets))
10+
<strong class="help-block">{{ $errors->{$errorBag}->first($nameWithoutBrackets) }}</strong>
1111
@else
1212
<strong class="help-block">{{ $note }}</strong>
1313
@endif

src/views/email/vertical.blade.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="form-group{{ $errors->has($nameWithoutBrackets) ? ' has-error' : '' }}">
1+
<div class="form-group{{ $errors->{$errorBag}->has($nameWithoutBrackets) ? ' has-error' : '' }}">
22
<div class="row">
33
@if($label)
44
{{ Form::label($name, $label, ['class' => 'content-label col-md-2']) }}
@@ -11,8 +11,8 @@
1111
{{ Form::email($name, $value, array_merge(['class' => 'form-control'], $attributes)) }}
1212

1313
@if($inlineValidation)
14-
@if($errors->has($nameWithoutBrackets))
15-
<strong class="help-block">{{ $errors->first($nameWithoutBrackets) }}</strong>
14+
@if($errors->{$errorBag}->has($nameWithoutBrackets))
15+
<strong class="help-block">{{ $errors->{$errorBag}->first($nameWithoutBrackets) }}</strong>
1616
@else
1717
<strong class="help-block">{{ $note }}</strong>
1818
@endif

0 commit comments

Comments
 (0)