Commit 32bbbb5f authored by Sylvain's avatar Sylvain

Mise à jour de Field Bt3

parent 7ddad67c
......@@ -299,7 +299,7 @@ class Field2Bt3
$source = data_get($this->options, 'source');
$attrs_default = [
'class' => $this->makeClasses('form-check-input'),
'class' => '',
'type' => 'radio',
'name' => $this->makeName(),
];
......@@ -325,7 +325,7 @@ class Field2Bt3
$this->is_multiple = count(data_get($this->options, 'source', [])) > 1;
$attrs_default = [
'class' => $this->makeClasses('form-check-input'),
'class' => '',
'type' => 'checkbox',
'name' => $this->makeName(),
];
......@@ -474,7 +474,7 @@ class Field2Bt3
$attr_selected = 'selected';
break;
case 'checkbox':
$template = '<div class="form-check[INLINE]">' . PHP_EOL;
$template = '<div class="checkbox[INLINE]">' . PHP_EOL;
$template .= ' <input id="[ID]-[VALUE]" name="[NAME]" value="[VALUE]"[ATTRIBUTES][SELECTED]/>' . PHP_EOL;
$template .= ' <label class="form-check-label" for="[ID]-[VALUE]">[LABEL]</label>' . PHP_EOL;
$template .= '</div>' . PHP_EOL;
......@@ -855,14 +855,7 @@ class Field2Bt3
$render = '';
if (!empty($this->prefix)) {
$template = '<div class="input-group-prepend">' . PHP_EOL;
if (preg_match('/<(button|img).*/', $this->prefix)) {
$template .= ' %s' . PHP_EOL;
} else {
$template .= ' <div class="input-group-text">%s</div>' . PHP_EOL;
}
$template .= '</div>' . PHP_EOL;
$template = '<div class="input-group-addon">%s</div>' . PHP_EOL;
$render = sprintf($template, $this->prefix);
}
return $render;
......@@ -878,14 +871,7 @@ class Field2Bt3
$render = '';
if (!empty($this->suffix)) {
$template = '<div class="input-group-append">' . PHP_EOL;
if (preg_match('/<(button|img).*/', $this->suffix)) {
$template .= ' %s' . PHP_EOL;
} else {
$template .= ' <div class="input-group-text">%s</div>' . PHP_EOL;
}
$template .= '</div>' . PHP_EOL;
$template = '<div class="input-group-addon">%s</div>' . PHP_EOL;
$render = sprintf($template, $this->suffix);
}
......@@ -925,10 +911,10 @@ class Field2Bt3
private function renderLabel(): string
{
$render = '';
$class = '';
$class = 'control-label';
if ($this->getAttr('required')) {
$class .= 'required';
$class .= ' required';
}
if ($this->inline && ($this->getAttr('type') != 'checkbox' || $this->getAttr('type') != 'radio')) {
......@@ -960,6 +946,16 @@ class Field2Bt3
$render = $renderField;
$template = '';
$errors = session('errors', collect());
$getter_name = $this->makeGetterName();
$validation = '';
if ($errors->has($getter_name)) {
$validation = ' has-error';
} else if (!is_null(old($getter_name))) {
$validation = ' has-success';
}
$templateInline = '<div class="form-group row">' . PHP_EOL;
$templateInline .= '%s%s';
$templateInline .= ' <div class="col-sm-10">' . PHP_EOL;
......@@ -967,7 +963,7 @@ class Field2Bt3
$templateInline .= ' </div>' . PHP_EOL;
$templateInline .= '</div>' . PHP_EOL;
$templateClassic = '<div class="form-group">' . PHP_EOL;
$templateClassic = '<div class="form-group%s">' . PHP_EOL;
$templateClassic .= '%s%s' ;
$templateClassic .= '%s';
$templateClassic .= '</div>' . PHP_EOL;
......@@ -978,10 +974,12 @@ class Field2Bt3
// Si prefixe ou suffixe
if (!empty($this->prefix) || !empty($this->suffix)) {
$class_size = empty($this->size) ? '' : ' input-group-' . $this->size;
$class = empty($this->size) ? '' : ' input-group-' . $this->size;
$class .= $validation;
$render = vsprintf($templatePrefix, [
$class_size,
$class,
str_indent($this->renderPrefix(), 1),
str_indent($render, $noindent ? 0 : 1),
str_indent($this->renderSuffix(), 1),
......@@ -1007,6 +1005,7 @@ class Field2Bt3
$render = str_indent($render, $noindent ? 0 : 1);
$render = vsprintf($templateClassic, [
$validation,
str_indent($this->renderLabel(), 1),
str_indent($this->renderPopover(), 1),
$render,
......
<?php
namespace Goldenscarab\Modulus\Service\Field\Facades;
use Illuminate\Support\Facades\Facade;
class FieldBt3 extends Facade
{
protected static function getFacadeAccessor()
{
return 'FieldBt3';
}
}
......@@ -32,6 +32,10 @@ class FieldServiceProvider extends ServiceProvider
$this->app->bind('Field2', function() {
return new \Goldenscarab\Modulus\Service\Field\Field2;
});
$this->app->bind('FieldBt3', function() {
return new \Goldenscarab\Modulus\Service\Field\FieldBt3;
});
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment