Commit bfb6e925 authored by Sylvain's avatar Sylvain

Field v1

parent 65b8025f
......@@ -17,114 +17,329 @@ composer require goldenscarab/modulus-service-field
Laravel 5.8 uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider.
## Usage simple
## Liste des champs disponibles
- [Input](#Input)
- [Select](#Select)
- [Textarea](#Textarea)
- [Checkbox](#Checkbox)
- [Radio](#Radio)
- [Range](#Range)
- [Toggle](#Toggle)
- [File](#File)
- [Image](#Image)
- [PDF](#Image)
- [Video](#Image)
- [Code](#Code)
#### Input
```php
// Simple
{!! Field::input([
'label' => 'Total',
'name' => 'total',
'value' => 23.4,
]); !!}
// Avancé
{!! Field::input([
'label' => 'Champs text',
'name' => 'my_field_name'
'label' => 'Total',
'name' => 'total',
'value' => 23.4,
'prefix' => '<i class="fa fa-money"></i>',
'suffix' => '€',
'help' => 'Taxe comprise',
'indice' => 1,
'inline' => true,
'attributes' => [
'id' => 'total-final',
'type' => 'text',
'class' => 'text-danger',
'placeholder' => '123,30',
'onchange' => "console.log('change')",
'style' => 'background-color: #c3c3c3;',
'data-type' => 'column',
'disabled' => true,
'readonly' => true,
'required' => true,
'autocomplete' => true,
'autofocus' => true
],
'popover' => [
'placement' => 'right',
'title' => 'Information',
'content' => "Le montant est calculé selon les éléments communiqué. Il peux néanmoins variée suivant d'autre facteurs non pris en compte"
],
]) !!}
```
#### Select
```php
// Simple
{!! Field::select([
'label' => 'Menu déroulant',
'name' => 'my_field_name',
'options' => [
1 => 'Item 1',
2 => 'Item 2'
]
'source' => [
1 => 'Item 1',
2 => 'Item 2'
]
]
]) !!}
// Simple avec groupes
{!! Field::select([
'label' => 'Menu déroulant',
'name' => 'my_field_name',
'value' => 23,
'options' => [
'default' => ['value' => '', 'label' => 'Choisir...'],
'source' => [
'Groupe 1' => [
23 => 'Élement 23',
24 => 'Élement 24',
25 => 'Élement 25',
],
'Groupe 2' => [
26 => 'Élement 26',
27 => 'Élement 27',
28 => 'Élement 28',
]
]
]
]) !!}
// Avancé avec Callback
{!! Field::select([
'label' => 'Collection',
'name' => 'collection',
'value' => [2, 4],
'class' => 'select2',
'size' => 'sm',
'prefix' => '<i class="fa fa-list"></i>',
'suffix' => '<i class="fa fa-hand-paper-o"></i>',
'indice' => 34,
'attributes' => [
'class' => 'select2',
'multiple' => true,
'required' => true
],
'options' => [
'source' => $collection,
'default' => ['value' => '', 'label' => 'Choisir...'],
'value' => ':id',
'label' => ['callback' => [
'function' => 'strtoupper',
'args' => ['template' => [
'format' => '%s - %s',
'args' => [':title', ':value']
]]
]],
]
]); !!}
// Avancé avec Data
{!! Field::select([
'label' => 'Ville',
'name' => 'city_id',
'value' => 2,
'placeholder' => "Choisir...",
'options' => [
'source' => $collection,
'default' => ['value' => '', 'label' => 'Choisir une ville...'],
'value' => ':id',
'label' => ['template' => [
'format' => '%s - %s',
'args' => [':city.cp', ':city.name']
]],
'attributes' => [
'data-cp' => ':city.cp',
'data-city' => ':city.name',
]
]
]) !!}
```
#### Textarea
```php
{!! Field::textarea([
'label' => 'Zone de texte',
'name' => 'my-field'
'label' => 'Contenu',
'name' => 'content',
'value' => $item->content,
'attributes' => [
'class' => 'text-editor',
'rows' => 15,
]
]) !!}
```
#### Image
#### Checkbox
```php
{!! Field::image([
'label' => 'Champs image',
'name' => 'my_field_image',
// Simple
{!! Field::checkbox([
'label' => 'Choix multiple',
'name' => 'my_field_name',
'value' => [2, 3],
'inline' => true,
'options' => [
'source' => [
1 => 'Item 1',
2 => 'Item 2',
3 => 'Item 3'
]],
]) !!}
// Avancé
{!! Field::checkbox([
'label' => 'Mon Champs',
'name' => 'mon-champs',
'value' => ['value-2', 'value-3'],
'inline' => true,
'options' => [
'source' => $collection,
'value' => ':id',
'label' => ['callback' => [
'function' => 'strtoupper',
'args' => ['template' => [
'format' => '%s - %s',
'args' => [':title', ':value']
]]
]],
'attributes' => [
'data-one' => ':data.data1',
'data-two' => ':data.data2',
'class' => [
'condition' => [
'value' => ':id',
'operator' => '==',
'comparator' => 2,
'true' => 'my-class-id-2',
]
]
]
]
] !!}
```
Has identique field with `pdf`, `video`, `file`
#### Radio
```php
// Simple
{!! Field::radio([
'label' => 'Choix',
'name' => 'my_field_name',
'value' => 2,
'inline' => true,
'options' => [
'source' => [
1 => 'Item 1',
2 => 'Item 2',
3 => 'Item 3'
]],
]) !!}
// Avancé
{!! Field::radio([
'label' => 'Mon Champs',
'name' => 'mon-champs',
'value' => 'value-2',
'options' => [
'source' => $collection,
'value' => ':id',
'label' => ['callback' => [
'function' => 'strtoupper',
'args' => ['template' => [
'format' => '%s - %s',
'args' => [':title', ':value']
]]
]],
'attributes' => [
'data-one' => ':data.data1',
'data-two' => ':data.data2',
'class' => [
'condition' => [
'value' => ':id',
'operator' => '==',
'comparator' => 2,
'true' => 'my-class-id-2',
]
]
]
]
]) !!}
```
## Usage advanced
#### Input
#### Range
```php
{!! Field::input([
'label' => 'Moneyt',
'name' => 'money',
'value' => $item->money,
'size' => 'sm',
'placeholder' => 'ex : 1 200,00',
'is_required' => true,
'prefix' => '<i class="fa fa-money"></i>',
'suffix' => '€',
{!! Field::range([
'label' => 'Zoom',
'name' => 'zoom',
'value' => 7,
'attributes' => [
'min' => -10,
'max' => 10,
],
]) !!}
```
#### Select
#### Toggle
```php
// Exemple 1
{!! Field::select([
'label' => 'Menu déroulant',
'name' => 'my_field_name',
'value' => $item->my_field_name,
'placeholder' => 'Choisir ...',
'size' => 'sm',
'is_required' => true,
'options' => [
'collect' => $collection,
'value' => 'id',
'text' => ['code', 'libelle'],
'callback' => 'strtoupper',
'template' => 'Code : %s Libellé : %s',
'datas' => ['attr' => 'id']
{!! Field::toggle([
'label' => 'Toggle',
'name' => 'toggle',
'value' => 1,
'attributes' => [
'data-on' => 'Actif',
'data-off' => 'Inactif',
'data-onstyle' => 'success',
'data-offstyle' => 'danger',
'data-toggle' => 'toggle',
'data-width' => '75',
'data-size' => 'xs'
]
]) !!}
```
// Exemple 2 with groups
{!! Field::select([
'label' => 'Menu déroulant',
'name' => 'my_field_name',
'value' => $item->my_field_name,
'placeholder' => 'Choisir ...',
'size' => 'sm',
'is_required' => true,
'options' => [
'Groupe 1' => [
23 => 'Élement 23',
24 => 'Élement 24',
25 => 'Élement 25',
],
'Groupe 2' => [
26 => 'Élement 26',
27 => 'Élement 27',
28 => 'Élement 28',
]
]
#### File
```php
{!! Field::file([
'label' => 'Uploader',
'name' => 'csv',
'prefix' => 'Fichier',
'attributes' => ['placeholder' => 'Aucun fichier choisi']
]) !!}
```
#### Image
```php
{!! Field::image([
'label' => 'Champs image',
'name' => 'my_field_image',
'value' => $item->my_field_image,
'placeholder' => 'ex: /upload/folder/image.png',
'suffix' => '<i class="fa fa-file-image-o mr-2"></i> Choisir une image',
'is_required' => true,
]) !!}
'label' => 'Champs image',
'name' => 'my_field_image',
'value' => 'image.png',
'suffix' => '<i class="fa fa-file-image-o mr-2"></i> Choisir une image',
'attributes' => [
'placeholder' => 'ex: /upload/folder/image.png',
'required' => true,
]
]) !!}
```
Has identique field with `pdf`, `video`
#### Code
```php
{!! Field::code([
'label' => 'Contenu',
'name' => 'content',
'value' => 'function foo(items) {
var x = "All this is syntax highlighted";
return x;
}',
'style' => 'min-height: 400px;',
'is_required' => true,
'datas' => array(
'language' => 'javascript',
'readonly' => 'false',
'beautiful' => 'false',
)
]) !!}
```
Click [here](example.md) for more examples
......
......@@ -27,12 +27,13 @@
"Goldenscarab\\Modulus\\Service\\Field\\FieldServiceProvider"
],
"aliases": {
"Field": "Goldenscarab\\Modulus\\Service\\Field\\Facades\\Field"
"Field": "Goldenscarab\\Modulus\\Service\\Field\\Facades\\Field",
"Field2": "Goldenscarab\\Modulus\\Service\\Field\\Facades\\Field2"
}
}
},
"require-dev": {
"laravel/framework": "5.8.x",
"goldenscarab/modulus-helpers": "0.0.x"
"goldenscarab/modulus-helpers": "0.1.x"
}
}
# Service Field
## Utilisation minimale
### Input
```php
// Exemple
{!! Field::input([
'label' => 'Champs text',
'name' => 'my_field_name'
]) !!}
```
### Select
```php
// Exemple
{!! Field::select([
'label' => 'Menu déroulant',
'name' => 'my_field_name',
'options' => [
1 => 'Item 1',
2 => 'Item 2'
]
]) !!}
```
### Textarea
```php
// Exemple
{!! Field::textarea([
'label' => 'Zone de texte',
'name' => 'my-field'
]) !!}
```
### Checkbox
```php
// Exemple
{!! Field::checkbox([
'label' => 'Menu déroulant',
'name' => 'my_field_name',
'options' => 'options' => [
1 => 'Item 1',
2 => 'Item 2'
]
]) !!}
```
### Radio
```php
// Exemple
{!! Field::radio([
'label' => 'Menu déroulant',
'name' => 'my_field_name',
'options' => 'options' => [
1 => 'Item 1',
2 => 'Item 2'
]
]) !!}
```
### Honeypot
```php
// Exemple
{!! Field::honeypot() !!}
```
### Range
```php
// Exemple
{!! Field::range([
'label' => 'Zoom',
'name' => 'zoom',
]) !!}
```
### Toggle
```php
{!! Field::toggle([
'label' => 'Toggle',
'name' => 'toggle',
'datas' => [
'on' => 'Actif',
'off' => 'Inactif',
'toggle' => 'toggle'
]
]) !!}
```
### Vidéo
```php
{!! Field::video([
'label' => 'Vidéo',
'name' => 'video',
'value' => $item->video,
]) !!}
```
### Image
```php
{!! Field::image([
'label' => 'Champs image',
'name' => 'my_field_image',
]) !!}
```
### PDF
```php
{!! Field::pdf([
'label' => 'Champs pdf',
'name' => 'my_field_pdf',
]) !!}
```
### Fichier
```php
{!! Field::file([
'label' => 'Uploader',
'name' => 'csv',
]) !!}
```
### Par page
```php
{!! Field::perpage() !!}
```
### Recherche
```php
{!! Field::search() !!}
```
### Visibilité / Statut
```php
{!! Field::publish($item->status) !!}
```
### Code source
```php
{!! Field::code([
'label' => 'Contenu',
'name' => 'content',
'value' => $item->content,
'style' => 'min-height: 400px;',
'is_required' => true,
'datas' => array(
'language' => 'html',
'readonly' => 'false',
'beautiful' => 'false',
)
]) !!}
```
## Utilisation avancée
### Input
```php
// Exemple
{!! Field::input([
'label' => 'Champs text',
'name' => 'my_field_name',
'value' => $item->my_field_name,
'size' => 'sm',
'placeholder' => 'ex : mon texte',
'is_required' => true,
]) !!}
```
### Select
Affichage simple
```php
// Exemple
{!! Field::select([
'label' => 'Menu déroulant',
'name' => 'my_field_name',
'value' => $item->my_field_name,
'placeholder' => 'Choisir ...',
'is_required' => true,
'options' => [
'collect' => $collection,
'value' => 'nom_champs_valeur',
'text' => 'nom_champs_texte',
]
]) !!}
```
Affichage avancé
```php
// Exemple 1
{!! Field::select([
'label' => 'Menu déroulant',
'name' => 'my_field_name',
'value' => $item->my_field_name,
'placeholder' => 'Choisir ...',
'size' => 'sm',
'is_required' => true,
'options' => [
'collect' => $collection,
'value' => 'id',
'text' => ['code', 'libelle'],
'callback' => 'strtoupper',
'template' => 'Code : %s Libellé : %s',
'datas' => ['attr' => 'id']
]
]) !!}
// Exemple 2 avec des groupes
{!! Field::select([
'label' => 'Menu déroulant',
'name' => 'my_field_name',
'value' => $item->my_field_name,
'placeholder' => 'Choisir ...',
'size' => 'sm',
'is_required' => true,
'options' => [
'Groupe 1' => [
23 => 'Élement 23',
24 => 'Élement 24',
25 => 'Élement 25',
],
'Groupe 2' => [
26 => 'Élement 26',
27 => 'Élement 27',
28 => 'Élement 28',
]
]
]) !!}
```
### Textarea
```php
// Exemple
{!! Field::textarea([
'label' => 'Zone de texte',
'name' => 'my-field',
'class' => 'text-success',
'value' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. ',
'rows' => 8,
'prefix' => '<i class="fa fa-tag"></i>',
'is_required' => true,
]) !!}
```
### Checkbox
```php
// Exemple
{!! Field::checkbox([
'label' => 'Choix multiple',
'name' => 'my_field_name',
'values' => [2, 3],
'class' => 'checkbox-xl',
//'is_inline' => true,
'options' => [
1 => 'Item 1',
2 => 'Item 2',
3 => 'Item 3'
]
]) !!}
```
### Radio
```php
// Exemple
{!! Field::radio([
'label' => 'Choix unique',
'name' => 'my_field_name',
'value' => 2,
'is_inline' => true,
'options' => [
1 => 'Item 1',
2 => 'Item 2',
3 => 'Item 3'
]
]) !!}
```
### Range
```php
// Exemple
{!! Field::range([
'label' => 'Zoom',
'name' => 'zoom',
'min' => 0,
'max' => 20,
]) !!}
```
### Toggle
```php
{!! Field::toggle([
'label' => 'Toggle',
'name' => 'toggle',
'value' => 1,
'datas' => [
'on' => 'Actif',
'off' => 'Inactif',
'onstyle' => 'success',
'offstyle' => 'danger',
'toggle' => 'toggle',
'width' => '75',
'size' => 'xs'
]
]) !!}
```
### Image
```php
{!! Field::image([
'label' => 'Champs image',
'name' => 'my_field_image',
'value' => $item->my_field_image,
'placeholder' => 'ex: /upload/folder/image.png',
'suffix' => '<i class="fa fa-file-image-o mr-2"></i> Choisir une image',
'is_required' => true,
]) !!}
```
### Vidéo
```php
{!! Field::video([
'label' => 'Champs video',
'name' => 'my_field_video',
'value' => $item->my_field_video,
'placeholder' => 'ex: /upload/folder/video.mp4',
'suffix' => '<i class="fa fa-file-video-o mr-2"></i> Choisir une vidéo',
'is_required' => true,
]) !!}
```
### PDF
```php
{!! Field::pdf([
'label' => 'Champs pdf',
'name' => 'my_field_pdf',
'value' => $item->my_field_pdf,
'placeholder' => 'ex: /upload/folder/file.pdf',
'suffix' => '<i class="fa fa-file-pdf-o mr-2"></i> Choisir un PDF',
'is_required' => true,
]) !!}
```
### Fichier
```php
{!! Field::file([
'label' => 'Uploader',
'name' => 'csv',
'prefix' => 'Fichier',
'placeholder' => 'Aucun fichier choisi'
]) !!}
```
## Les paramètres
| Param | Type | Defaut | Description |
| --------------- |----------| -------|----------------------------------------|
| id | string | null | Attribut *id* du champs |
| type | string | null | Attribut *text* d'un champs input |
| label | string | null | Etiquette du champs |
| name | string | null | Attribut *name* du champs |
| value | string | null | Valeur du champs |
| class | string | null | Attribut *class* du champs |
| prefix | string | null | Texte dans partie gauche du champs |
| suffix | string | null | Texte dans partie droite du champs |
| placeholder | string | null | Texte visible avant la saisie |
| help | string | null | Message d'aide sous le champs |
| indice | mixte | null | Passe le champs en mode tableau |
| style | string | null | Attribut *style* du champs |
| rows | integer | null | Attribut *rows* d'un champs select |
| min | integer | null | Limite maximal pour un champs digital |
| max | integer | null | Limite minimal pour un champs digital |
| size | string | null | Taille du champs (sm | lg) |
| is_required | boolean | false | Rend le champs obligatoire |
| is_inline | boolean | false | Affichage du champs en mode ligne |
| is_multiple | boolean | false | Select en mode multiple |
| is_autocomplete | boolean | false | Active l'autocompletion |
| is_disabled | boolean | false | Desactive le champs |
| is_readonly | boolean | false | Champt en lecture seule |
| popover | array | [] | Ajoute un icone d'information |
| datas | array | [] | Ajoute des attributs data-... |
| options | array | [] | Liste des options d'un champs select |
| values | array | [] | Liste des valeurs d'une champs multi |
| attributes | array | [] | Liste des attributs supplémentaires |
## Exemples
### Champs input
```php
// Nom
{!! Field::input([
'label' => 'Nom',
'name' => 'name',
'type' => 'text',
'prefix' => '<i class="fa fa-user"></i>',
'is_required' => true,
'placeholder' => "ex : Martin",
'value' => $item->name
]) !!}
// Email
{!! Field::input([
'label' => 'Email',
'name' => 'email',
'type' => 'email',
'prefix' => '<i class="fa fa-envelope"></i>',
'is_required' => true,
'placeholder' => "ex : user@mail.tld",
'help' => 'Votre email sera utilisé comme identifiant',
'value' => $item->email
]) !!}
// Téléphone
{!! Field::input([
'label' => 'Téléphone',
'name' => 'phone',
'type' => 'tel',
'prefix' => '<i class="fa fa-phone"></i>',
'placeholder' => "ex : 0102030405",
'value' => $item->phone
]) !!}
// Adresse
{!! Field::input([
'label' => 'Adresse',
'name' => 'address',
'type' => 'text',
'prefix' => '<i class="fa fa-map-marker"></i>',
'placeholder' => "ex : 247, Rue des jardin",
'value' => $item->address
]) !!}
// Couleur
{!! Field::input([
'label' => 'Couleur',
'name' => 'color',
'type' => 'color',
'prefix' => '<i class="fa fa-paint-brush"></i>',
'value' => $item->color
]) !!}
// Date
{!! Field::input([
'label' => 'Date',
'name' => 'date',
'value' => $item->date,
'class' => 'datepicker',
'prefix' => '<i class="fa fa-calendar"></i>',
]) !!}
```
### Champs select
```php
// Publié
{!! Field::select([
'label' => 'Publié',
'name' => 'published',
'prefix' => '<i class="fa fa-globe"></i>',
'value' => $item->published
'options' => [
0 => 'Brouillon',
1 => 'En ligne'
]
]) !!}
// Civilité
{!! Field::select([
'label' => 'Civilité',
'name' => 'civility',
'value' => $item->civility,
'placeholder' => "Choisir...",
'options' => [
0 => 'Monsieur',
1 => 'Madame',
2 => 'Mademoiselle'
]
]) !!}
// Choix d'une ville avec possibilité de filtrage des valeurs affichées sur attribut data (hide|show)
{!! Field::select([
'label' => 'Ville',
'name' => 'city_id',
'value' => $item->city_id,
'placeholder' => "Choisir une ville...",
'options' => [
'collect' => $villes,
'value' => 'id',
'text' => ['departement.zipcode', 'name'], // Utilisation des relations
'template' => '%s - %s',
'datas' => [
'departement' => 'departement.department_code', // Utilisation des relations
'region' => 'region.name',
]
]
]) !!}
// Choix de catégories ( multiple choix )
{!! Field::select([
'label' => 'Catégorie',
'name' => 'categories',
'values' => $item->categories()->pluck('id')->toArray(), // Multi valeurs
'class' => 'select2',
'is_multiple' => true,
'options' => [
'collect' => $categories,
'value' => 'id',
'text' => 'title',
]
]) !!}
```
### Champs textarea
```php
// Champs contenu Wysiwyg
{!! Field::textarea([
'label' => 'Contenu',
'name' => 'content',
'value' => $item->content,
'class' => 'text-editor',
'rows' => 15,
'popover' => [
'placement' => 'right',
'title' => 'Le contenu',
'content' => "Le contenu est le coeur de l'article. Grâce à l'éditeur vous pouvez formater le rendu selon votre goût."
]
]) !!}
// Champs commentaire
{!! Field::textarea([
'label' => 'Commentaire',
'name' => 'comment',
'value' => $item->comment,
'rows' => 3,
]) !!}
```
## Possibilitiées d'un champs
Voici un exemple montrant les possibilités d'un champs input
```php
{!! Field::input([
'id' => 'total-final',
'type' => 'text',
'label' => 'Total',
'name' => 'total',
'value' => 23.4,
'class' => 'text-danger',
'prefix' => '<i class="fa fa-money"></i>',
'suffix' => '€',
'placeholder' => "123,30",
'help' => 'Taxe comprise',
'indice' => 1,
'style' => 'background-color: #c3c3c3;',
'attributes' => [
'onchange' => 'console.log("change")',
'title' => [
'source' => $data_source,
'template' => '%s - %s',
'attributes' => ['type.id', 'type.label'],
'callback' => 'ucfirst'
]
],
'datas' => [
'type' => 'column',
'reference' => [
'source' => $data_source,
'template' => '%s-%s',
'attributes' => ['type.id', 'type.code'],
'callback' => 'ucfirst'
]
],
'is_inline' => true,
'is_disabled' => true,
'is_readonly' => true,
'is_required' => true,
'is_autocomplete' => true,
'is_autofocus' => true,
'popover' => [
'placement' => 'right',
'title' => 'Information',
'content' => "Le montant est calculé selon les éléments communiqué. Il peux néanmoins variée suivant d'autre facteurs non pris en compte"
],
]) !!}
```
Exemple de filtre dans une liste
```php
{!! Field::select([
'name' => 'role',
'value' => Request::get('role'),
'class' => 'form-control-sm w-100',
'placeholder' => '-- Rôles --',
'attributes' => ['onchange' => "document.getElementById('filter-form').submit();"],
'options' => [
'collect' => $roles,
'value' => 'id',
'text' => 'display_name',
]
]) !!}
```
......@@ -2,106 +2,87 @@
namespace Goldenscarab\Modulus\Service\Field\Compose;
use stdClass;
use Illuminate\Support\Str;
use \Illuminate\Support\HtmlString;
use Goldenscarab\Modulus\Helpers\Dynamik;
class Field2Bt4
{
private $type;
private $label;
private $id;
private $class;
private $name;
private $value;
private $placeholder;
private $prefix;
private $suffix;
private $help;
private $attributes;
private $indice;
private $style;
private $rows;
private $min;
private $max;
private $size;
private $inline;
private $required;
private $help;
private $popover;
private $options;
private $is_multiple;
private $is_autocomplete;
private $is_autofocus;
private $is_disabled;
private $is_required;
private $is_readonly;
private $is_inline;
private $_datas;
private $_values;
private $_options;
private $_popover;
private $_attributes;
public function __construct($attrs = [])
public function __construct(array $args)
{
$this->setAttrs($attrs);
$this->label = data_get($args, 'label');
$this->name = data_get($args, 'name');
$this->value = data_get($args, 'value');
$this->prefix = data_get($args, 'prefix');
$this->suffix = data_get($args, 'suffix');
$this->attributes = data_get($args, 'attributes', []);
$this->indice = data_get($args, 'indice');
$this->size = data_get($args, 'size');
$this->inline = data_get($args, 'inline');
$this->required = data_get($args, 'required');
$this->help = data_get($args, 'help');
$this->popover = data_get($args, 'popover');
$this->options = data_get($args, 'options');
}
/**
* Retourne le rendu du champs Code avec ses paramètres
* Retourne le rendu du champs Code Source
*
* @return string Le rendu du champs
*/
public function renderCodeEditor():string
{
$template = '<div id="editor-%s" class="code-editor"%s>%s</div>' . PHP_EOL;
$template = '<div id="editor-%s"%s>%s</div>' . PHP_EOL;
$template .= '<textarea id="%s" name="%s" style="display: none;">%s</textarea>';
$this->_datas['target'] = '#' . $this->id;
$attrs_default = [
'class' => $this->makeClasses('code-editor'),
'data-target' => '#' . $this->makeID(),
'style' => 'min-height: 300px;',
'data-language' => 'html'
];
$this->attributes = $this->updateAttributes($attrs_default);
$render = vsprintf($template, [
$this->id,
$this->renderFieldAttrs(['style']),
e($this->getValue()),
$this->id,
$this->name,
e($this->getValue()),
$this->makeID(),
$this->renderAttributes($this->attributes),
e($this->makeValue()),
$this->makeID(),
$this->makeName(),
e($this->makeValue()),
]);
return $render;
}
/**
* Retourne le rendu du champs File avec ses paramètres
* Retourne le rendu du champs File
*
* @return string Le rendu du champs
*/
public function renderFile(): string
{
$template = '<div class="custom-file">' . PHP_EOL;
$template .= ' %s' . PHP_EOL;
$template .= ' <input%s />' . PHP_EOL;
$template .= ' <label class="custom-file-label" for="%s">%s</label>' . PHP_EOL;
$template .= ' <script type="text/javascript">' . PHP_EOL;
$template .= ' document.getElementById(\'%s\').addEventListener(\'change\', function(e) {' . PHP_EOL;
......@@ -114,29 +95,36 @@ class Field2Bt4
$template .= ' </script>' . PHP_EOL;
$template .= '</div>';
$this->class = str_replace('form-control', 'custom-file-input', $this->class);
$this->type = 'file';
$attrs_default = [
'id' => $this->makeID('id'),
'class' => $this->makeClasses('custom-file-input'),
'type' => 'file',
'name' => $this->makeName(),
];
$this->attributes = $this->updateAttributes($attrs_default);
$render = vsprintf($template, [
$this->renderInput(),
$this->id,
$this->placeholder,
$this->id,
$this->renderAttributes($this->attributes),
$this->makeID('id'),
$this->getAttr('placeholder'),
$this->makeID('id'),
]);
return $render;
}
/**
* Retourne le rendu du champs PDF avec ses paramètres
* Retourne le rendu du champs PDF
*
* @return string Le rendu du champs
*/
public function renderPdf(): string
{
$template = '<div class="input-group">' . PHP_EOL;
$template .= ' <div class="input-group-prepend">' . PHP_EOL;
$template .= ' <div class="input-group-text text-danger">' . PHP_EOL;
$template .= ' <i class="fa fa-file-pdf-o" aria-hidden="true"></i>' . PHP_EOL;
$template .= ' <div class="input-group-text">' . PHP_EOL;
$template .= ' %s' . PHP_EOL;
$template .= ' </div>' . PHP_EOL;
$template .= ' </div>' . PHP_EOL;
$template .= ' %s' . PHP_EOL;
......@@ -148,9 +136,10 @@ class Field2Bt4
$template .= '</div>';
$render = vsprintf($template, [
$this->prefix ?? '<i class="fa fa-file-pdf-o text-danger"></i>',
$this->renderInput(),
$this->id,
'#' . $this->id,
$this->makeID('id'),
'#' . $this->makeID('id'),
'application/pdf',
$this->suffix ?? '<i class="fa fa-file-pdf-o mr-2"></i>Choisir PDF'
]);
......@@ -162,7 +151,44 @@ class Field2Bt4
}
/**
* Retourne le rendu du champs Video avec ses paramètres
* Retourne le rendu du champs Image
*
* @return string Le rendu du champs
*/
public function renderImage(): string
{
$template = '<div class="input-group img-group">' . PHP_EOL;
$template .= ' <div class="input-group-prepend">' . PHP_EOL;
$template .= ' <img id="thumb-%s" class="image-thumb" src="%s" alt="thumb">' . PHP_EOL;
$template .= ' </div>' . PHP_EOL;
$template .= ' %s' . PHP_EOL;
$template .= ' <div class="input-group-append">' . PHP_EOL;
$template .= ' <button class="btn btn-outline-secondary popupfinder" type="button" id="btn-%s" data-thumb="%s" data-field="%s" data-mimes="%s">' . PHP_EOL;
$template .= ' %s' . PHP_EOL;
$template .= ' </button>' . PHP_EOL;
$template .= ' </div>' . PHP_EOL;
$template .= '</div>';
$render = vsprintf($template, [
$this->makeID('id'),
empty($this->makeValue()) ? url('images/default.svg') : url($this->makeValue()),
$this->renderInput(),
$this->makeID('id'),
'#thumb-' . $this->makeID('id'),
'#' . $this->makeID('id'),
'image',
$this->suffix ?? '<i class="fa fa-picture-o mr-2"></i>Choisir image'
]);
$this->prefix = null;
$this->suffix = null;
return $render;
}
/**
* Retourne le rendu du champs Video
*
* @return string Le rendu du champs
*/
public function renderVideo(): string
......@@ -170,7 +196,7 @@ class Field2Bt4
$template = '<div class="input-group">' . PHP_EOL;
$template .= ' <div class="input-group-prepend">' . PHP_EOL;
$template .= ' <div class="input-group-text">' . PHP_EOL;
$template .= ' <i class="fa fa-video-camera" aria-hidden="true"></i>' . PHP_EOL;
$template .= ' %s' . PHP_EOL;
$template .= ' </div>' . PHP_EOL;
$template .= ' </div>' . PHP_EOL;
$template .= ' %s' . PHP_EOL;
......@@ -182,9 +208,10 @@ class Field2Bt4
$template .= '</div>';
$render = vsprintf($template, [
$this->prefix ?? '<i class="fa fa-video-camera"></i>',
$this->renderInput(),
$this->id,
'#' . $this->id,
$this->makeID('id'),
'#' . $this->makeID('id'),
'video',
$this->suffix ?? '<i class="fa fa-file-video-o mr-2"></i>Choisir vidéo'
]);
......@@ -196,31 +223,30 @@ class Field2Bt4
}
/**
* Retourne le rendu du champs Image avec ses paramètres
* @return string Le rendu du champs
* Retourne le rendu d'un champs Folder
*
* @return string
*/
public function renderImage(): string
public function renderFolder(): string
{
$render = '';
$template = '<div class="input-group img-group">' . PHP_EOL;
$template .= ' <div class="input-group-prepend">' . PHP_EOL;
$template .= ' <img id="thumb-%s" class="image-thumb" src="%s" alt="thumb">' . PHP_EOL;
$template .= ' %s' . PHP_EOL;
$template .= ' </div>' . PHP_EOL;
$template .= ' %s' . PHP_EOL;
$template .= ' <div class="input-group-append">' . PHP_EOL;
$template .= ' <button class="btn btn-outline-secondary popupfinder" type="button" id="btn-%s" data-thumb="%s" data-field="%s" data-mimes="%s">' . PHP_EOL;
$template .= ' <button class="btn btn-outline-secondary popupfinder" type="button" id="btn-%s" data-field="%s" data-folder="true">' . PHP_EOL;
$template .= ' %s' . PHP_EOL;
$template .= ' </button>' . PHP_EOL;
$template .= ' </div>' . PHP_EOL;
$template .= '</div>';
$render = vsprintf($template, [
$this->id,
empty($this->getValue()) ? url('images/default.svg') : url($this->getValue()),
$this->prefix ?? '<img class="image-thumb" src="'.url('images/folder.jpg').'" alt="thumb">',
$this->renderInput(),
$this->id,
'#thumb-' . $this->id,
'#' . $this->id,
'image',
$this->makeID('id'),
'#' . $this->makeID('id'),
$this->suffix ?? '<i class="fa fa-picture-o mr-2"></i>Choisir image'
]);
......@@ -231,59 +257,95 @@ class Field2Bt4
}
/**
* Retourne le rendu du champs Toogle avec ses paramètres
* @return string Le rendu du champs toggle
* Retourne le rendu d'un champs Toogle
*
* @return string
*/
public function renderToggle(): string
{
$availables = ['id', 'class', 'name', 'is_disabled', 'is_required', 'is_readonly', 'style'];
$render = '';
$template = '<div class="toogle">' . PHP_EOL;
$template .= ' <input type="checkbox" value="1" %s%s />' . PHP_EOL;
$template .= ' <input value="1"%s />' . PHP_EOL;
$template .= '</div>';
$attrs_default = [
'id' => $this->makeID(),
'class' => $this->makeClasses(),
'name' => $this->makeName(),
'type' => 'checkbox',
'checked' => $this->makeValue() == 1
];
$this->attributes = $this->updateAttributes($attrs_default);
$render = vsprintf($template, [
$this->renderFieldAttrs($availables),
$this->getValue() == 1 ? ' checked' : ''
$this->renderAttributes($this->attributes)
]);
return $render;
}
/**
* Retourne le rendu du champs radio avec ses paramètres
* @return string Le rendu du champs radio
* Retourne le rendu d'un champs de type Radio
*
* @return string
*/
public function renderRadio(): string
{
$this->is_multiple = false;
$this->class = str_replace('form-control', 'form-check-input', $this->class);
$render = '';
$source = data_get($this->options, 'source');
$attrs_default = [
'class' => $this->makeClasses('form-check-input'),
'type' => 'radio',
'name' => $this->makeName(),
];
$this->attributes = $this->updateAttributes($attrs_default);
$render = $this->renderOptions('checkbox');
return $this->renderCheckedOptions('radio');
return $render;
}
/**
* Retourne le rendu du champs checkbox avec ses paramètres
* @return string Le rendu du champs checkbox
* Retourne le rendu d'un champs de type Checkbox
*
* @return string
*/
public function renderCheckbox(): string
{
$this->is_multiple = count($this->_options) > 1;
$this->class = str_replace('form-control', 'form-check-input', $this->class);
$render = '';
$source = data_get($this->options, 'source');
$this->is_multiple = count(data_get($this->options, 'source', [])) > 1;
$attrs_default = [
'class' => $this->makeClasses('form-check-input'),
'type' => 'checkbox',
'name' => $this->makeName(),
];
$this->attributes = $this->updateAttributes($attrs_default);
$render = $this->renderOptions('checkbox');
return $this->renderCheckedOptions('checkbox');
return $render;
}
/**
* Retourne le rendu du champs range avec ses paramètres
* @return string Le rendu du champs range
* Retourne le rendu d'un champs de type range
*
* @return string
*/
public function renderRange(): string
{
$availables = ['id', 'class', 'name', 'value', 'min', 'max', 'is_disabled', 'ris_equired', 'is_readonly', 'style'];
$render = '';
$functionName = camel_case($this->name) . 'ShowValue';
$template = '<input type="range" %s oninput="%s(this.value)" />' . PHP_EOL;
$func_name = Str::camel($this->makeName()) . 'ShowValue';
$template = '<input%s oninput="%s(this.value)" />' . PHP_EOL;
$template .= '<span id="%s">%s&nbsp;</span>'. PHP_EOL;
$template .= '<script type="text/javascript">' . PHP_EOL;
$template .= ' function %s(newValue) {' . PHP_EOL;
......@@ -291,484 +353,429 @@ class Field2Bt4
$template .= ' }' . PHP_EOL;
$template .= '</script>';
$attrs_default = [
'id' => $this->makeID(),
'class' => $this->makeClasses(),
'type' => 'range',
'name' => $this->makeName(),
'value' => $this->makeValue()
];
$this->attributes = $this->updateAttributes($attrs_default);
$render = vsprintf($template, [
$this->renderFieldAttrs($availables),
$functionName,
$this->id . '-value',
$this->value,
$functionName,
$this->id . '-value'
$this->renderAttributes($this->attributes),
$func_name,
$this->makeID() . '-value',
$this->makeValue(),
$func_name,
$this->makeID() . '-value',
]);
return $render;
}
/**
* Retourne le rendu de 2 champs pot de miel (my-name & my-time)
* @return string Le rendu des 2 champs pot de miel
* Retourne le rendu d'un champs de type Textarea
*
* @return string
*/
public function renderHoneypot(): string
public function renderTextarea(): string
{
$template = "";
$template .= '<div class="d-none">' . PHP_EOL;
$template .= ' <input type="text" name="my-name" value="%s" />' . PHP_EOL;
$template .= ' <input type="text" name="my-time" value="%s" />' . PHP_EOL;
$template .= '</div>';
$render = '';
$template = '<textarea %s>%s</textarea>';
$attrs_default = [
'id' => $this->makeID(),
'class' => $this->makeClasses(),
'name' => $this->makeName(),
];
$this->attributes = $this->updateAttributes($attrs_default);
$render = vsprintf($template, [
null,
encrypt(time())
$this->renderAttributes($this->attributes),
$this->makeValue()
]);
return $render;
}
/**
* Retourne le rendu du champs textarea avec ses paramètres
* @return string Le rendu du champs textarea
* Retourne le rendu d'un champs de type Select
*
* @return string
*/
public function renderTextarea(): string
public function renderSelect(): string
{
$availables = ['id', 'class', 'name', 'placeholder', 'is_autocomplete', 'is_autofocus', 'is_disabled', 'is_required', 'is_readonly', 'rows', 'style'];
$render = '';
$template = '<select%s>' . PHP_EOL;
$template .= '%s';
$template .= '</select>';
$template = '<textarea %s>%s</textarea>';
$attrs_default = [
'id' => $this->makeID(),
'class' => $this->makeClasses(),
'name' => $this->makeName(),
];
$this->attributes = $this->updateAttributes($attrs_default);
$render = vsprintf($template, [
$this->renderFieldAttrs($availables),
str_replace("\r\n", '[CR]', $this->getValue())
$this->renderAttributes($this->attributes),
str_indent($this->renderOptions('select'), 1)
]);
return $render;
}
/**
* Retourne le rendu du champs select avec ses paramètres;
* @return string Le rendu du champs select
* Retourne le rendu d'un champs de type Input
*
* @return string
*/
public function renderSelect(): string
public function renderInput(): string
{
$availables = ['id', 'class', 'name', 'is_multiple', 'is_disabled', 'is_required', 'is_readonly', 'style'];
$render = '';
$template = '<input%s />';
$template = '<select %s>' . PHP_EOL;
$template .= '%s';
$template .= '</select>';
$attrs_default = [
'id' => $this->makeID(),
'class' => $this->makeClasses(),
'type' => 'text',
'name' => $this->makeName(),
'value' => $this->makeValue()
];
$this->attributes = $this->updateAttributes($attrs_default);
$render = vsprintf($template, [
$this->renderFieldAttrs($availables),
$this->renderIndent($this->renderOptions(), 1),
$this->renderAttributes($this->attributes)
]);
return $render;
}
/**
* Retourne le rendu du champs input avec ses paramètres;
* @return string Le rendu du champs input
*/
public function renderInput(): string
private function renderOptions($type): string
{
$availables = ['id', 'type', 'class', 'name', 'value', 'placeholder', 'is_autocomplete', 'is_autofocus', 'is_disabled', 'is_required', 'is_readonly', 'style'];
$render = '';
$template = '<input %s />';
if (!array_key_exists('source', $this->options)) {
throw new \InvalidArgumentException("The `source` key is required in options");
}
if (is_null($this->type)) {
$this->type = 'text';
switch ($type) {
case 'select':
$template = '<option value="[VALUE]"[ATTRIBUTES][SELECTED]>[LABEL]</option>' . PHP_EOL;
$sub_template = '<optgroup label="[LABEL]">' . PHP_EOL;
$sub_template .= '[VALUE]';
$sub_template .= '</optgroup>' . PHP_EOL;
$attr_selected = 'selected';
break;
case 'checkbox':
$template = '<div class="form-check[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;
$sub_template = '';
$attr_selected = 'checked';
$template = str_replace('[INLINE]', ($this->inline ? ' form-check-inline' : ''), $template);
$template = str_replace('[ID]', $this->makeID(), $template);
$template = str_replace('[NAME]', $this->makeName(), $template);
// Merge des attributs
$options_attrs = data_get($this->options, 'attributes', []);
$attributes = $this->updateAttributes($options_attrs);
data_set($this->options, 'attributes', $attributes);
case 'radio':
break;
default:
exit;
break;
}
$render = sprintf($template, $this->renderFieldAttrs($availables));
// Detection options dynamiques
if(array_keys_exists(['value', 'label'], $this->options)) {
$render = $this->renderDynamicOptions($template, $sub_template, $attr_selected);
} else {
$render = $this->renderStaticOptions($template, $sub_template, $attr_selected);
}
return $render;
}
/**
* Retourne le rendu d'un champs avec son environnement
* @param string $renderField Le rendu du champs
* @return string Le rendu de l'environnement du champs
*/
public function renderWrapFieldEnvironment(string $renderField, $noindentfield = false): string
private function renderDynamicOptions($template, $sub_template, $attr_selected): string
{
$render = $renderField;
$template = '';
$render = '';
$datas = data_get($this->options, 'source');
$value = data_get($this->options, 'value');
$label = data_get($this->options, 'label');
$attrs = data_get($this->options, 'attributes', []);
$templateInline = '<div class="form-group row">' . PHP_EOL;
$templateInline .= '%s%s';
$templateInline .= ' <div class="col-sm-10">' . PHP_EOL;
$templateInline .= '%s';
$templateInline .= ' </div>' . PHP_EOL;
$templateInline .= '</div>' . PHP_EOL;
// Ajout de la valeur par défaut
$render .= $this->renderDefaultOption();
$templateClassic = '<div class="form-group">' . PHP_EOL;
$templateClassic .= '%s%s' ;
$templateClassic .= '%s';
$templateClassic .= '</div>' . PHP_EOL;
// Ajout des options
foreach ($datas as $data) {
$dynamik = new Dynamik($data);
$templatePrefix = '<div class="input-group%s">'. PHP_EOL;
$templatePrefix .= '%s%s%s';
$templatePrefix .= '</div>'. PHP_EOL;
// Préparation de l'option
$option_value = $dynamik->getValue($value);
$option_label = $dynamik->getValue($label);
// Si prefixe ou suffixe
if (!empty($this->prefix) || !empty($this->suffix)) {
$class_size = empty($this->size) ? '' : ' input-group-' . $this->size;
// Préparation des attributs
$attributes = [];
foreach($attrs as $name => $val) {
$attr_val = $dynamik->getValue($val);
$attributes[$name] = is_array($attr_val) ? array_filter($attr_val) : $attr_val;
}
$option_attrs = $this->renderAttributes(array_filter($attributes));
// Valeur sélectionnée ?
$selected = $this->isActiveOption($option_value) ? ' ' . $attr_selected : '';
$temp = str_replace('[VALUE]', $option_value, $template);
$temp = str_replace('[ATTRIBUTES]', $option_attrs, $temp);
$temp = str_replace('[SELECTED]', $selected, $temp);
$render .= str_replace('[LABEL]', $option_label, $temp);
$render = vsprintf($templatePrefix, [
$class_size,
$this->renderIndent($this->renderPrefix(), 1),
$this->renderIndent($render, $noindentfield ? 0 : 1),
$this->renderIndent($this->renderSuffix(), 1),
]);
}
return $render;
}
// Ajout des messages
$render .= $this->renderHelp() . $this->renderValidationMessage();
private function renderStaticOptions($template, $sub_template, $attr_selected): string
{
$render = '';
// Affichage en mode inline
if ($this->is_inline && ($this->type != 'checkbox' || $this->type != 'radio')) {
$render = $this->renderIndent($render, $noindentfield ? 0 : 2);
$datas = data_get($this->options, 'source');
$attributes = data_get($this->options, 'attributes', []);
$render = vsprintf($templateInline, [
$this->renderIndent($this->renderLabel(), 1),
$this->renderIndent($this->renderPopover(), 1),
$render,
]);
} else {
$render = $this->renderIndent($render, $noindentfield ? 0 : 1);
// Ajout de la valeur par défaut
$render .= $this->renderDefaultOption();
$render = vsprintf($templateClassic, [
$this->renderIndent($this->renderLabel(), 1),
$this->renderIndent($this->renderPopover(), 1),
$render,
if (is_array($datas)) {
foreach($datas as $value => $label) {
// Préparation des attributs
$attrs = $this->renderAttributes(array_filter($attributes));
// Cas d'un sous niveau
if (is_array($label)) {
$opt_group = '';
foreach ($label as $_value => $_label) {
if (is_iterable($_label) || (is_object($_label) && !method_exists($value, '__toString'))) {
throw new \InvalidArgumentException("Invalid value of options attribute : " . $_value);
}
$selected = $this->isActiveOption($_value) ? ' ' . $attr_selected : '';
$temp = str_replace('[VALUE]', $_value, $template);
$temp = str_replace('[ATTRIBUTES]', $attrs, $temp);
$temp = str_replace('[SELECTED]', $selected, $temp);
$opt_group .= str_replace('[LABEL]', $_label, $temp);
}
$temp = str_replace('[LABEL]', $value, $sub_template);
$render .= str_replace('[VALUE]', str_indent($opt_group, 1), $temp);
} else {
$selected = $this->isActiveOption($value) ? ' ' . $attr_selected : '';
$temp = str_replace('[VALUE]', $value, $template);
$temp = str_replace('[ATTRIBUTES]', $attrs, $temp);
$temp = str_replace('[SELECTED]', $selected, $temp);
$render .= str_replace('[LABEL]', $label, $temp);
}
}
}
return $render;
}
private function renderDefaultOption()
{
$render = '';
$template = '<option value="%s"%s%s>%s</option>' . PHP_EOL;
$default = data_get($this->options, 'default', []);
// Ajout de la valeur par défaut
if (!empty($default)) {
$render .= vsprintf($template, [
data_get($default, 'value'),
$this->getAttr('required') ? ' disabled hidden' : '',
$this->isActiveOption(data_get($default, 'value')) ? ' selected' : '',
data_get($default, 'label')
]);
}
return $render;
}
/**
* Retourne le rendu d'une chaine de caractère en HTML
* @param String $string La chains de caractères à traiter
* @return String Le rendu HTML
*/
public function renderHTML($string): HtmlString
private function isActiveOption($data)
{
return new HtmlString($string);
$value = $this->makeValue();
if (is_array($value)) {
return in_array($data, $value);
} else {
return strval($value) === strval($data);
}
}
/**
* Retourne le rendu de la partie aide d'un champs (sous le champs)
* @return string Le rendu de la partie aide
* Mise à jour des attributs défini par l'utilisateur avec les attributs par défaut du champs
*
* @param array $attrs
* @param array $default
* @return array Un tableau des attributes du champs
*/
private function renderHelp(): string
private function updateAttributes($default = [])
{
$render = '';
$attrs = $this->attributes;
if (!empty($this->help)) {
$template = '<small class="form-text text-muted text-right mt-0">%s</small>' . PHP_EOL;
$render = sprintf($template, $this->help);
// Etape 1 - Nettoyage des attributs indésirables (name et value, n'ont rien à faire là)
unset($attrs['name'], $attrs['value']);
// Etape 2 - Fusion des attributs avec les valeurs par défaut
$attributes = array_merge($default, $attrs);
// Etape 3 - 2ème passe avec fusion des valeurs de type tableau
foreach ($attributes as $name => $value) {
if (is_array(data_get($default, $name)) || is_array(data_get($attrs, $name))) {
$attr_value = is_array(data_get($attrs, $name)) ? data_get($attrs, $name) : [data_get($attrs, $name)];
$default_value = is_array(data_get($default, $name)) ? data_get($default, $name) : [data_get($default, $name)];
$attributes[$name] = array_filter(array_merge($default_value, $attr_value));
}
}
return $render;
$attributes = array_filter($attributes);
return $attributes;
}
/**
* Retoune le rendu de la partie prefixe du champs
* @return string Le rendu du prefixe
* Constuction de l'ID du champs
*
* @return string
*/
private function renderPrefix(): string
private function makeID()
{
$render = '';
$id = '';
if (!empty($this->prefix)) {
$template = '<div class="input-group-prepend">' . PHP_EOL;
if (preg_match('/<button.*/', $this->prefix)) {
$template .= ' %s' . PHP_EOL;
} else {
$template .= ' <div class="input-group-text">%s</div>' . PHP_EOL;
}
$template .= '</div>' . PHP_EOL;
$render = sprintf($template, $this->prefix);
$id .= 'field-';
$id .= Str::slug($this->name);
if (!empty($this->indice) && !is_bool($this->indice)) {
$id .= '-' . $this->indice;
}
return $render;
return $id;
}
/**
* Retourne le rendu de la partie suffixe du champs
* @return string Le rendu du suffixe
* Construction du nom de du champs
*
* @return string
*/
private function renderSuffix(): string
private function makeName(): string
{
$render = '';
$name = $this->name;
if (!empty($this->suffix)) {
$template = '<div class="input-group-append">' . PHP_EOL;
if (preg_match('/<button.*/', $this->suffix)) {
$template .= ' %s' . PHP_EOL;
} else {
$template .= ' <div class="input-group-text">%s</div>' . PHP_EOL;
}
$template .= '</div>' . PHP_EOL;
if ($this->indice === true) {
$name .= '[]';
} else if (!is_null($this->indice) && !is_bool($this->indice)) {
$name .= '[' . $this->indice . ']';
}
$render = sprintf($template, $this->suffix);
if ($this->getAttr('multiple')) {
$name .= '[]';
}
return $render;
if ($this->is_multiple) {
$name .= '[]';
}
return $name;
}
/**
* Retourne le rendu de la popover (description du champs)
* @return string Le rendu de la popover
* Récupération de la valeur du champs
*
* @return Mixte
*/
private function renderPopover(): string
private function makeValue()
{
$render = '';
if (!empty($this->_popover)) {
$template = '<span class="text-info popup-help" data-toggle="popover" data-placement="%s" title="%s" data-content="%s">' . PHP_EOL;
$template .= ' <i class="fa fa-info-circle"></i>' . PHP_EOL;
$template .= '</span>' . PHP_EOL;
$render = vsprintf($template, [
data_get($this->_popover, 'placement', 'right'),
data_get($this->_popover, 'title', 'Informations'),
data_get($this->_popover, 'content'),
]);
}
return $render;
$getter_name = $this->makeGetterName();
return old($getter_name, $this->value);
}
/**
* Retourne le rendu du label du champs
* @return string Le rendu du label
* Construction des classes du champs
*
* @param string $default
* @return array
*/
private function renderLabel(): string
private function makeClasses($default = 'form-control'): array
{
$render = '';
$class = '';
$classes = [];
$classes[] = $default;
if ($this->is_required) {
$class .= 'required';
}
$errors = session('errors', collect());
$getter_name = $this->makeGetterName();
if ($this->is_inline && ($this->type != 'checkbox' || $this->type != 'radio')) {
$class .= 'col-sm-2';
if ($errors->has($getter_name)) {
$classes[] = 'is-invalid';
} else if (!is_null(old($getter_name))) {
$classes[] = 'is-valid';
}
if (!empty($this->label)) {
$template = '<label for="%s"%s>%s</label>' . PHP_EOL;
$render = vsprintf($template, [
$this->id,
strlen($class) > 0 ? ' class="' . $class . '"' : '',
$this->label
]);
// Si une taille est spécifiée && aucun préfixe ou suffixe
if (!empty($this->size) && empty($this->prefix) && empty($this->suffix)) {
$classes[] = 'form-control-' . $this->size;
}
$classes = array_filter($classes);
return $render;
return $classes;
}
/**
* Rendu d'optiond de type checked
*
* @param string $type type de champs à rendre
* @return string Le rendu du champs
*/
private function renderCheckedOptions(string $type = 'checkbox')
{
$availables = ['id', 'class', 'name', 'value', 'is_disabled', 'is_required', 'is_readonly', 'style'];
$template = '<div class="form-check%s%s">' . PHP_EOL;
$template .= ' <input type="%s" %s%s%s/>' . PHP_EOL;
$template .= ' <label class="form-check-label" for="%s">%s</label>' . PHP_EOL;
$template .= '</div>' . PHP_EOL;
$render = "";
$current_value = old($this->name, $this->is_multiple ? $this->_values : $this->value);
$options = $this->optionsModeling();
foreach ($options as $option) {
// Gestion de la valeur
$this->value = $option->getOptionValue();
if (is_array($current_value)) {
$checked = in_array($this->value, $current_value);
} else {
$checked = $this->value == $current_value;
}
// Gestion des ID
if (!is_bool($this->indice)) {
$this->id = str_slug($this->name . '-' . $this->indice . '-' . $this->value);
} else {
$this->id = str_slug($this->name . '-' . $this->value);
}
$render .= vsprintf($template, [
$this->is_disabled ? ' disabled' : '',
$this->is_inline ? ' form-check-inline' : '',
$type,
$this->renderFieldAttrs($availables),
$option->getDatasRender(),
$checked ? ' checked' : '',
$this->id,
$option->getOptionLabel()
]);
}
return $render;
}
/**
* Modélisation des options
* Collection d'Option modélisées
* Retourne le nom de type getter pour un champs (utile pour old(), $errors, ...)
*
* @return string
*/
private function optionsModeling()
private function makeGetterName(): string
{
$options = collect();
if (is_array($this->_options)) {
$this->checkOptionsValue();
if (isset($this->_options['collect'])) {
foreach ($this->_options['collect'] as $key => $item) {
$option = new Option();
$option->setSource($item);
$option->setLabelParam(data_get($this->_options, 'text'));
$option->setValueParam(data_get($this->_options, 'value'));
$option->setDatas(data_get($this->_options, 'datas'));
$option->setClass(data_get($this->_options, 'class'));
$option->setTemplate(data_get($this->_options, 'template'));
$option->setCallback(data_get($this->_options, 'callback'));
$option->setAttributes(data_get($this->_options, 'attributes'));
$options->push($option);
}
} else {
foreach ($this->_options as $key => $item) {
$option = new Option();
$option->setSource([$key => $item]);
$options->push($option);
$name = $this->name;
}
}
if ($this->indice === true) {
$name .= '.*';
} else if (!is_null($this->indice)) {
$name .= '.' . $this->indice;
}
return $options;
return $name;
}
/**
* Retourne le rendu d'options d'un menu déroulant select
* @return string Le rendu des options
* Retourne le rendu d'un tableau d'attributs avec leur valeurs
*
* @param array $attrs
* @return string
*/
private function renderOptions(): string
private function renderAttributes(array $attrs): string
{
$render = '';
$template = '<option value="%s"%s>%s</option>' . PHP_EOL;
$template_group = '<optgroup label="%s">%s</optgroup>' . PHP_EOL;
$default = '<option value=""' . ($this->is_required ? ' disabled hidden' : '') . ' selected >%s</option>' . PHP_EOL;
if (!is_null($this->placeholder)) {
$render = sprintf($default, $this->placeholder);
}
// Détection d'une collection source
if (isset($this->_options['collect'])) {
$this->checkOptionsValue();
foreach ($this->_options['collect'] as $key => $item) {
$attrs = "";
// L'élément courant correspond à la valeur du champs
$field_name = is_int($this->indice) ? $this->name . '.' . $this->indice : $this->name;
$field_value = old($field_name, $this->is_multiple ? $this->_values : $this->value);
$item_value = data_get($item, $this->_options['value']);
// Attributs data-*
if (isset($this->_options['datas']) && is_array($this->_options['datas'])) {
foreach ($this->_options['datas'] as $name => $value) {
$attrs .= $this->renderDatas([$name => data_get($item, $value)]);
}
$attrs = ' ' . trim($attrs);
}
if ((is_array($field_value) && in_array($item_value, $field_value)) ||
(!is_array($field_value) && strval($field_value) === strval($item_value))) {
$attrs .= ' selected';
}
$text = data_get($this->_options, 'text');
$callback = data_get($this->_options, 'callback');
// Gestion d'un template
if (isset($this->_options['template'])) {
// 1ère passe : ajout d'un template pour l'affichage du texte de l'option
$render .= vsprintf($template, [
data_get($item, $this->_options['value']),
$attrs,
$this->objectToString($this->_options['template'], $text, $callback, $item)
]);
} else {
$render .= vsprintf($template, [
data_get($item, $this->_options['value']),
$attrs,
$this->objectToString(null, $text, $callback, $item)
]);
}
}
} else {
foreach ($this->_options as $value => $text) {
$opt_group = '';
// Cas d'un sous niveau
if (is_array($text)) {
foreach ($text as $value_ => $text_) {
if (empty($this->name)) {
$attrs = strval($this->value) === strval($value_) ? ' selected' : '';
} else {
$attrs = strval(old($this->name, $this->value)) === strval($value_) ? ' selected' : '';
}
$opt_group .= vsprintf($template, [
$value_,
$attrs,
$text_
]);
}
$render .= vsprintf($template_group, [
$value,
$opt_group
]);
} else {
if (empty($this->name)) {
$attrs = strval($this->value) === strval($value) ? ' selected' : '';
} else {
$attrs = strval(old($this->name, $this->value)) === strval($value) ? ' selected' : '';
}
$render = '';
$render .= vsprintf($template, [
$value,
$attrs,
$text
]);
}
foreach ($attrs as $name => $value) {
if ($value === true) {
$render .= vsprintf(' %s', [$name]);
} else if (is_array($value)) {
$render .= vsprintf(' %s="%s"', [$name, implode(' ', $value)]);
}else {
$render .= vsprintf(' %s="%s"', [$name, $value]);
}
}
......@@ -777,6 +784,7 @@ class Field2Bt4
/**
* Retourne le rendu d'un message d'erreur de validation
*
* @return string Le rendu du message
*/
private function renderValidationMessage()
......@@ -795,523 +803,217 @@ class Field2Bt4
}
/**
* Retourne le rendu des attributs d'un champs
* @param array $availables Liste des attributs pouvant composer le champs
* @return string Le rendu des attributs
*/
private function renderFieldAttrs(array $availables, $fixvalue = false): string
{
$attrs = get_object_vars($this);
$render = '';
$template = '%s="%s" ';
$except_empty_attr = ['value'];
foreach ($attrs as $attr => $value) {
// On traite uniquement les attributs autorisés
if (!in_array($attr, ['label', 'prefix', 'suffix'])) {
// On ne traite pas les attributs avec une valeur vide
if (!in_array($attr, $except_empty_attr) && empty($value)) {
continue;
}
// Traitement des cas particuliers
switch ($attr) {
case 'value':
if ($fixvalue) {
$val = $this->value;
} else {
$val = $this->getValue();
}
break;
case 'class':
$val = $this->getClasses();
break;
case 'name' :
$val = $value;
// Mode indice
if (!is_null($this->indice)) {
$val .= '['. ($this->indice !== true ? $this->indice : '') .']';
}
if ($this->is_multiple) {
$val .= '[]';
}
break;
default:
if (is_bool($value)) {
$val = $value;
} else {
$val = $this->getDataValue($value);
}
break;
}
if ($value === true) {
$render .= $attr . ' ';
} else if ($value != false) {
$render .= vsprintf($template, [$attr, $val]);
}
}
}
// Attributs supplémentaires
if (!is_null($this->_attributes) && is_array($this->_attributes)) {
foreach ($this->_attributes as $attr => $value) {
if (is_array($value)) {
$value_ = $this->objectToString(
data_get($value, 'template'),
data_get($value, 'attributes'),
data_get($value, 'callback'),
data_get($value, 'source')
);
} else {
$value_ = $value;
}
$render .= vsprintf($template, [$attr, $value_]);
}
}
// Ajout des datas
//$render .= $this->renderDatas($this->_datas);
return trim($render);
}
/**
* Retourne le rendu avec indentation d'un texte
* @param string $text Le texte à traiter
* @param Integer $nb Le nombre d'indentation à appliquer
* @return string Le rendu avec indentation
* Retourne le rendu de la partie aide d'un champs (sous le champs)
*
* @return string Le rendu de la partie aide
*/
private function renderIndent($text, $nb): string
private function renderHelp(): string
{
$indent = ' ';
$render = '';
$real_indent = '';
for ($i = 1; $i <= $nb; $i++) {
$real_indent .= $indent;
}
$lines = explode(PHP_EOL, $text);
foreach ($lines as $line) {
if (!empty($line)) {
$render .= $real_indent . $line . PHP_EOL;
}
if (!empty($this->help)) {
$template = '<small class="form-text text-muted text-right mt-0">%s</small>' . PHP_EOL;
$render = sprintf($template, $this->help);
}
return $render;
}
/**
* Retourne le rendu des attributs datas
* @param array $datas La liste des attributs data
* @return string Le rendu avec les attributs data
*/
// protected function renderDatas($datas): string
// {
// $render = '';
// if (!empty($datas) && is_array($datas)) {
// $template = 'data-%s="%s" ';
// foreach ($datas as $name => $value) {
// if (is_array($value)) {
// $value_ = $this->objectToString(
// data_get($value, 'template'),
// data_get($value, 'attributes'),
// data_get($value, 'callback'),
// data_get($value, 'source')
// );
// } else {
// $value_ = $value;
// }
// $render .= vsprintf($template, [$name, $value_]);
// }
// }
// return $render;
// }
/**
* Retourne la liste de toutes les classes du champs
* @return string Les classes du champs
* Retoune le rendu de la partie prefixe du champs
*
* @return string Le rendu du prefixe
*/
private function getClasses(): string
private function renderPrefix(): string
{
$classes = $this->class . ' ' . $this->getValidationClass();
// Si une taille est spécifiée
if (!empty($this->size)) {
$render = '';
// Aucun préfixe ou suffixe
if (empty($this->prefix) && empty($this->suffix)) {
$classes .= ' ' . 'form-control-' . $this->size;
if (!empty($this->prefix)) {
$template = '<div class="input-group-prepend">' . PHP_EOL;
if (preg_match('/<button.*/', $this->prefix)) {
$template .= ' %s' . PHP_EOL;
} else {
$template .= ' <div class="input-group-text">%s</div>' . PHP_EOL;
}
}
return trim($classes);
}
/**
* Retourne la classe Bootstrap de validation du champs
* @return string La classe
*/
private function getValidationClass()
{
$errors = session('errors', collect());
$class = null;
$template .= '</div>' . PHP_EOL;
if ($errors->has($this->name)) {
$class = 'is-invalid';
} else if (!is_null($this->name) && !is_null(old($this->name))) {
$class = 'is-valid';
$render = sprintf($template, $this->prefix);
}
return $class;
return $render;
}
/**
* Vérifie la cohérence de l'attribut Options
* @return void
* Retourne le rendu de la partie suffixe du champs
*
* @return string Le rendu du suffixe
*/
private function checkOptionsValue()
private function renderSuffix(): string
{
if (isset($this->_options['collect'])) {
$render = '';
// Exceptions sur les paramètres
if (is_array($this->_options['text']) && empty($this->_options['template'])) {
throw new \InvalidArgumentException("Le paramètre options['template'] doit être présent lorsque options['text'] est un tableau");
}
if (isset($this->_options['template']) && !is_array($this->_options['text'])) {
throw new \InvalidArgumentException("Le paramètre options['text'] doit être un tableau lorsque options['template'] est présent");
if (!empty($this->suffix)) {
$template = '<div class="input-group-append">' . PHP_EOL;
if (preg_match('/<button.*/', $this->suffix)) {
$template .= ' %s' . PHP_EOL;
} else {
$template .= ' <div class="input-group-text">%s</div>' . PHP_EOL;
}
}
}
/**
* Retourne une valeur depuis old ou l'attribut
* @return string La valeur
*/
private function getValue()
{
$name = $this->name;
$template .= '</div>' . PHP_EOL;
if (is_null($name)) {
return ;
$render = sprintf($template, $this->suffix);
}
if (!is_null($this->indice)) {
$name .= '.' . $this->indice;
}
return old($name, $this->getDataValue($this->value));
return $render;
}
/**
* Retourne le rendu d'un template avec une liste de noms de colonnes
* @param string $template Le template servant au rendu
* @param string|array $display Le ou les noms de colonnes
* @param string $callback Fonction à appliquer sur la résultante
* @param Mix $item Objet source des donnés à afficher
* @param Mix $item Suppression des tags
* @return string Le rendu
*/
// protected function objectToString($template = null, $displays = null, $callback = null, $item, $strip = false)
// {
// // Création du texte à afficher
// $datas = [];
// // Convertion en tableau si besoin
// if (!is_iterable($displays)) {
// $displays = [$displays];
// }
// // Traitement du tableau de valeur à afficher
// foreach ($displays as $key => $display) {
// $data = mixte_get($item, $display);
// // Callback array
// if (is_array($callback) && isset($callback[$key]) && !is_null($callback[$key])) {
// $data = $callback[$key]($data);
// }
// $datas[] = $strip ? strip_tags($data) : $data;
// }
// // Traitement des % seuls pour éviter les conflits
// if (!empty($template)) {
// $template = preg_replace('/(%)[^0-9sd.\']/i', '%%"', $template);
// }
// // Traitement template & callback
// if (is_string($callback)) {
// if (empty($template)) {
// $string = call_user_func_array($callback, $datas);
// } else {
// $string = vsprintf($template, $datas);
// $string = $callback($string);
// }
// } else if (!empty($template)) {
// $string = vsprintf($template, $datas);
// } else {
// $string = $datas[0];
// }
// return $string;
// }
/**
* Retourne le rendu d'attributs avec leur valeur
* @param array $attrs Les attributs avec la colonne de l'object conteant la valeur
* @param Object $item Object contenant la valeur de l'attribut
* @return string Le rendu des attributs avec leur valeur
* Retourne le rendu de la popover (description du champs)
*
* @return string Le rendu de la popover
*/
private function renderAttributes($attrs = [], $source = null): string
private function renderPopover(): string
{
$render = '';
if (is_iterable($attrs)) {
$template = ' %s="%s"';
foreach ($attrs as $name => $data) {
if (is_null($source) || !is_array($data)) {
$value = $data;
} else if (is_array($data)) {
$value = $this->getDataValue($data, $source);
}
$render .= vsprintf($template, [$name, $value]);
if (!empty($this->popover)) {
$template = '<span class="text-info popup-help" data-toggle="popover" data-placement="%s" title="%s" data-content="%s">' . PHP_EOL;
$template .= ' <i class="fa fa-info-circle"></i>' . PHP_EOL;
$template .= '</span>' . PHP_EOL;
}
$render = vsprintf($template, [
data_get($this->popover, 'placement', 'right'),
data_get($this->popover, 'title', 'Informations'),
data_get($this->popover, 'content'),
]);
}
return $render;
}
/**
* Vérifier la validité d'un paramètre condition
* @param array|null $condition La condition si elle est disponible
* @param Objet $datas Les données dans lesquelles aller chercher la valeur à controler
* @return bollean True si la condition est valide, sinon false
* Retourne le rendu du label du champs
*
* @return string Le rendu du label
*/
private function checkCondition($condition, $datas): string
private function renderLabel(): string
{
$data = mixte_get($datas, mixte_get($condition, 'key'));
$value = mixte_get($condition, 'value');
$operator = mixte_get($condition, 'operator');
$default = true;
switch ($operator) {
case '==' :
$validated = $data == $value ? true : false;
break;
case '>' :
$validated = $data > $value ? true : false;
break;
case '<' :
$validated = $data < $value ? true : false;
break;
case '!=' :
$validated = $data != $value ? true : false;
break;
case '<=' :
$validated = $data <= $value ? true : false;
break;
case '>=' :
$validated = $data >= $value ? true : false;
break;
default :
$validated = $default;
}
return $validated;
}
$render = '';
$class = '';
/**
* Récupération d'une valeur en fonction de sa composition
* @param Mixed $value array pour une valeur dynamique ou string|int|float|bool pour une valeur statique
* @param Object $datas Objet dans lequel aller chercher la valeur si dynamique
* @param boolean $strip Supprimer les balises HTML dela valeur résultante
* @return Mixed La valeur
*/
private function getDataValue($value, $datas = null, $strip = false)
{
$_value = null;
if ($this->getAttr('required')) {
$class .= 'required';
}
if (is_array($value)) {
if ($this->inline && ($this->getAttr('type') != 'checkbox' || $this->getAttr('type') != 'radio')) {
$class .= ' col-sm-2';
}
// Si le tableau n'est pas de type associatif ['my-key'] devient ['key' => 'my-key']
if(array_keys($value) === range(0, count($value) - 1) && count($value) == 1) {
$value = ['key' => $value[0]];
}
if (!empty($this->label)) {
$template = '<label%s%s>%s</label>' . PHP_EOL;
$condition = data_get($value, 'condition');
if ($this->checkCondition($condition, $datas)) {
$_value = $this->dynamicFormatedValue(
data_get($value, 'template'),
data_get($value, 'key'),
data_get($value, 'value'),
data_get($value, 'callback'),
$datas,
$strip,
);
}
} else {
$_value = $value;
$render = vsprintf($template, [
$this->getAttr('id') ? ' for="' . $this->getAttr('id') . '"' : '',
strlen($class) > 0 ? ' class="' . trim($class) . '"' : '',
$this->label
]);
}
return $_value;
return $render;
}
/**
* Retourne le rendu formaté d'une valeur dynamique
* @param string $template Le template servant au formatage
* @param string|array $keys Le ou les nom de colonnes
* @param Mix $default Valeur par défaut
* @param string $callback Fonction callback à appeler pour traiter la valeur
* @param Mix $source Objet source pour récupérer la valeur dynamique
* @param boolean $strip Supprimer les balises HTML
* @return string Le rendu
* Retourne le rendu d'un champs avec son environnement
*
* @param string $renderField Le rendu du champs
* @return string Le rendu de l'environnement du champs
*/
private function dynamicFormatedValue($template = null, $keys = null, $default = null, $callback = null, $source, $strip = false)
public function renderWrapFieldEnvironment(string $renderField, $noindent = false): string
{
// Création du texte à afficher
$datas = [];
$render = $renderField;
$template = '';
// Convertion en tableau si besoin
if (!is_iterable($keys) && !is_null($keys)) {
$keys = [$keys];
$templateInline = '<div class="form-group row">' . PHP_EOL;
$templateInline .= '%s%s';
$templateInline .= ' <div class="col-sm-10">' . PHP_EOL;
$templateInline .= '%s';
$templateInline .= ' </div>' . PHP_EOL;
$templateInline .= '</div>' . PHP_EOL;
// Traitement du tableau de valeur à afficher
foreach ($keys as $key => $column) {
$templateClassic = '<div class="form-group">' . PHP_EOL;
$templateClassic .= '%s%s' ;
$templateClassic .= '%s';
$templateClassic .= '</div>' . PHP_EOL;
$data = mixte_get($source, $column, $default);
$templatePrefix = '<div class="input-group%s">'. PHP_EOL;
$templatePrefix .= '%s%s%s';
$templatePrefix .= '</div>'. PHP_EOL;
// Callback array
if (is_array($callback) && isset($callback[$key]) && !is_null($callback[$key])) {
$data = $callback[$key]($data);
}
// Si prefixe ou suffixe
if (!empty($this->prefix) || !empty($this->suffix)) {
$class_size = empty($this->size) ? '' : ' input-group-' . $this->size;
$datas[] = $strip ? strip_tags($data) : $data;
}
$render = vsprintf($templatePrefix, [
$class_size,
str_indent($this->renderPrefix(), 1),
str_indent($render, $noindent ? 0 : 1),
str_indent($this->renderSuffix(), 1),
$this->renderValidationMessage()
]);
$render .= $this->renderHelp();
} else {
if (!is_iterable($default)) {
$datas[] = $default;
} else {
$datas = $default;
}
}
// Traitement des % seuls pour éviter les conflits
if (!empty($template)) {
$template = preg_replace('/(%)[^0-9sd.\']/i', '%%"', $template);
$render .= $this->renderHelp() . $this->renderValidationMessage();
}
// Traitement template & callback
if (is_string($callback)) {
if (empty($template)) {
$string = call_user_func_array($callback, $datas);
} else {
$string = vsprintf($template, $datas);
$string = $callback($string);
}
// Affichage en mode inline
if ($this->inline && ($this->getAttr('type') != 'checkbox' || $this->getAttr('type') != 'radio')) {
$render = str_indent($render, $noindent ? 0 : 2);
} else if (!empty($template)) {
$string = vsprintf($template, $datas);
$render = vsprintf($templateInline, [
str_indent($this->renderLabel(), 1),
str_indent($this->renderPopover(), 1),
$render,
]);
} else {
$string = $datas[0];
$render = str_indent($render, $noindent ? 0 : 1);
$render = vsprintf($templateClassic, [
str_indent($this->renderLabel(), 1),
str_indent($this->renderPopover(), 1),
$render,
]);
}
return $string;
return $render;
}
/**
* Mise à jour des attributs depuis le tableau passé en paramètre
* @param Array $attrs Liste des attributs à traiter
* @return void
* Récupère la valeur d'un attribut dont le nom est passé en paramètre
*
* @param string $name Nom de l'attribut
* @return Mixte
*/
private function setAttrs($attrs)
private function getAttr($name)
{
$this->resetAttrs();
if (is_null($attrs)) {
return ;
}
// Liste des attributs autorisés
$attrs_available = array_map(function ($val) {
return trim($val, '_');
}, array_keys(get_object_vars($this)));
// Traitement des attributs
if (is_array($attrs)) {
foreach ($attrs as $attr => $value) {
//if (in_array($attr, $attrs_available)) {
//if (is_array($value)) {
//$this->{'_' . $attr} = $value;
//} else {
$this->{$attr} = $value;
//}
//} else {
//throw new \InvalidArgumentException("Le paramètre [" . $attr . "] n'est pas pris en charge");
//}
}
} else {
throw new \InvalidArgumentException("Type de paramètre invalide. Attendu : Tableau");
}
// Traitement de l'ID
if (is_null($this->id)) {
$this->id = 'field-' . $this->name;
}
if (!is_null($this->indice)) {
$this->id = $this->id . '-' . $this->indice;
}
$this->id = str_slug($this->id);
// Traitement de la classe
$this->class = 'form-control ' . $this->class;
$this->class = trim($this->class);
// Traitement sur la valeur
if (is_null($this->value)) {
$this->value = '';
}
return data_get($this->attributes, $name);
}
// Traitement sur la taille
if (!empty($this->size) && !in_array($this->size, ['sm', 'lg'])) {
throw new \InvalidArgumentException("La valeur pour le paramètre « size » est invalide");
}
private function setAttr($name, $value)
{
$this->attrbutes[$name] = $value;
}
/**
* Réinitialisation des attributs de constructions
* @return void
* Retourne le rendu d'une chaine de caractère en HTML
*
* @param String $string La chaines de caractères à traiter
* @return String Le rendu HTML
*/
private function resetAttrs()
public function renderHTML(string $string): HtmlString
{
$attrs = array_keys(get_object_vars($this));
foreach ($attrs as $attr) {
if (preg_match('/^_.*/', $attr)) {
$this->{$attr} = [];
} else if (preg_match('/^is_.*/', $attr)) {
$this->{$attr} = false;
} else {
$this->{$attr} = null;
}
}
return new HtmlString($string);
}
}
<?php
namespace Goldenscarab\Modulus\Service\Field\Facades;
use Illuminate\Support\Facades\Facade;
class Field2 extends Facade
{
protected static function getFacadeAccessor()
{
return 'Field2';
}
}
......@@ -5,7 +5,6 @@ namespace Goldenscarab\Modulus\Service\Field;
use Illuminate\Support\Facades\Request;
use Goldenscarab\Modulus\Service\Field\Compose\FieldBt4;
use Goldenscarab\Modulus\Service\Field\Compose\Field2Bt4;
class Field
......@@ -283,13 +282,4 @@ class Field
return $field->renderHTML($render);
}
public function input2($attrs = []): string
{
$field = new Field2Bt4($attrs);
$input = $field->renderInput();
$render = $field->renderWrapFieldEnvironment($input);
return $field->renderHTML($render);
}
}
<?php
namespace Goldenscarab\Modulus\Service\Field;
use Illuminate\Support\Facades\Request;
use Goldenscarab\Modulus\Service\Field\Compose\Field2Bt4 as FieldBt4;
class Field2
{
/**
* Retourne un champs code source
*
* @param array $attrs Attributs du champs
* @return string Le HTML du champs code source
*/
public function code($attrs): string
{
$field = new FieldBt4($attrs);
$code = $field->renderCodeEditor();
$render = $field->renderWrapFieldEnvironment($code, true);
return $field->renderHTML($render);
}
/**
* Retourne un champs select de choix de publication
* @param boolean $status La valeur du champs
* @return string Le HTML du champs de publication
*/
public function publish($status): string
{
$render = $this->select([
'label' => 'Visibilité',
'name' => 'status',
'prefix' => '<i class="fa fa-globe"></i>',
'value' => $status,
'attributes' => ['required' => true],
'options' => ['source' => [0 => 'Brouillon', 1 => 'En ligne']]
]);
return $render;
}
/**
* Retourne un champs de recherche dans une liste
* @return string Le HTML du champs de recherche
*/
public function search(): string
{
$render = $this->input([
'name' => 'search',
'value' => Request::get('search'),
'attributes' => [
'placeholder' => 'Recherche...',
'class' => 'form-control-sm',
],
'suffix' => '<button class="btn btn-outline-secondary btn-sm" type="submit" id="button-search"><i class="fa fa-search"></i></button>',
]);
return $render;
}
/**
* Retourne un champs select pour choisir le nombre d'éléments d'une liste à afficher
* @return string Le HTML du menu déroulant
*/
public function perpage(): string
{
$render = $this->select([
'label' => 'Lignes par page',
'value' => Request::fullUrlWithQuery(["perpage" => Request::get('perpage')]),
'attributes' => [
'class' => 'ml-2',
'placeholder' => 'Choisir...',
'onchange' => 'return document.location.href = this.value;'
],
'options' => [
'source' => [
Request::fullUrlWithQuery(["perpage" => 10]) => '10',
Request::fullUrlWithQuery(["perpage" => 15]) => '15',
Request::fullUrlWithQuery(["perpage" => 50]) => '50',
Request::fullUrlWithQuery(["perpage" => 100]) => '100',
Request::fullUrlWithQuery(["perpage" => 200]) => '200',
Request::fullUrlWithQuery(["perpage" => 500]) => '500',
Request::fullUrlWithQuery(["perpage" => 1000]) => '1000'
]
]
]);
return $render;
}
/**
* Retourne un champs file avec son environnement
* @param array $attrs Les attributs du champs
* @return string le HTML du champs et de son environnement
*/
public function file($attrs = []): string
{
$field = new FieldBt4($attrs);
$file = $field->renderFile();
$render = $field->renderWrapFieldEnvironment($file);
return $field->renderHTML($render);
}
/**
* Retourne un champs pdf avec son environnement
* @param array $attrs Les attributs du champs
* @return string le HTML du champs et de son environnement
*/
public function pdf($attrs = []): string
{
$field = new FieldBt4($attrs);
$image = $field->renderPdf();
$render = $field->renderWrapFieldEnvironment($image);
return $field->renderHTML($render);
}
/**
* Retourne un champs video avec son environnement
* @param array $attrs Les attributs du champs
* @return string le HTML du champs et de son environnement
*/
public function video($attrs = []): string
{
$field = new FieldBt4($attrs);
$image = $field->renderVideo();
$render = $field->renderWrapFieldEnvironment($image);
return $field->renderHTML($render);
}
/**
* Retourne un champs image avec son environnement
* @param array $attrs Les attributs du champs
* @return string le HTML du champs et de son environnement
*/
public function image($attrs = []): string
{
$field = new FieldBt4($attrs);
$image = $field->renderImage();
$render = $field->renderWrapFieldEnvironment($image);
return $field->renderHTML($render);
}
/**
* Retourne un champs dossier avec son environnement
* @param array $attrs Les attributs du champs
* @return string le HTML du champs et de son environnement
*/
public function folder($attrs = []): string
{
$field = new FieldBt4($attrs);
$folder = $field->renderFolder();
$render = $field->renderWrapFieldEnvironment($folder);
return $field->renderHTML($render);
}
/**
* Retourne un champs toggle avec son environnement
* @param array $attrs Les attributs du champs
* @return string Le HTML du champs et de son environnement
*/
public function toggle($attrs = []): string
{
$field = new FieldBt4($attrs);
$toggle = $field->renderToggle();
$render = $field->renderWrapFieldEnvironment($toggle);
return $field->renderHTML($render);
}
/**
* Retourne un champs radio avec son environnement
* @param array $attrs Les attributs du champs
* @return string Le HTML du champs et de son environnement
*/
public function radio($attrs = []): string
{
$field = new FieldBt4($attrs);
$radio = $field->renderRadio();
$render = $field->renderWrapFieldEnvironment($radio);
return $field->renderHTML($render);
}
/**
* Retourne un champs checkbox avec son environnement
* @param array $attrs Les attributs du champs
* @return string Le HTML du champs et de son environnement
*/
public function checkbox($attrs = []): string
{
$field = new FieldBt4($attrs);
$checkbox = $field->renderCheckbox();
$render = $field->renderWrapFieldEnvironment($checkbox);
return $field->renderHTML($render);
}
/**
* Retourne un champs range avec son environnement
* @param array $attrs Les attributs du champs
* @return string Le HTML du champs et de son environnement
*/
public function range($attrs = []): string
{
$field = new FieldBt4($attrs);
$range = $field->renderRange();
$render = $field->renderWrapFieldEnvironment($range);
return $field->renderHTML($render);
}
/**
* Retourne un champs pot de miel avec son environnement
* @return string Le HTML du champs et son environnement
*/
public function honeypot(): string
{
$field = new FieldBt4([
'name' => 'my-name',
'attributes' => ['class' => 'd-none']
]);
$input1 = $field->renderInput();
$field = new FieldBt4([
'name' => 'my-time',
'value' => encrypt(time()),
'attributes' => ['class' => 'd-none']
]);
$input2 = $field->renderInput();
return $field->renderHTML($input1 . $input2);
}
/**
* Retourne un champs textarea avec son environnement
* @param array $attrs Les attributs du champs
* @return string Le HTML du champs et de son environnement
*/
public function textarea($attrs = []): string
{
$field = new FieldBt4($attrs);
$textarea = $field->renderTextarea();
$render = $field->renderWrapFieldEnvironment($textarea, true);
return $field->renderHTML($render);
}
/**
* Retourne un champs select avec son environnement
* @param array $attrs Les attributs du champs
* @return string Le HTML du champs et de son environnement
*/
public function select($attrs = []): string
{
$field = new FieldBt4($attrs);
$select = $field->renderSelect();
$render = $field->renderWrapFieldEnvironment($select);
return $field->renderHTML($render);
}
/**
* Retourne un champs input avec son environnement
* @param array $attrs Les attributs du champs
* @return string Le HTML du champs et de son environnement
*/
public function input($attrs = []): string
{
$field = new FieldBt4($attrs);
$input = $field->renderInput();
$render = $field->renderWrapFieldEnvironment($input);
return $field->renderHTML($render);
}
}
......@@ -28,6 +28,10 @@ class FieldServiceProvider extends ServiceProvider
$this->app->bind('Field', function() {
return new \Goldenscarab\Modulus\Service\Field\Field;
});
$this->app->bind('Field2', function() {
return new \Goldenscarab\Modulus\Service\Field\Field2;
});
}
......
......@@ -7,22 +7,14 @@ use Illuminate\Support\Facades\File;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Goldenscarab\Modulus\Service\Field\Facades\Field;
use Goldenscarab\Modulus\Service\Field\Facades\Field2 as Field;
/**
* ./vendor/bin/phpunit ./vendor/goldenscarab/modulus-service-field/tests/FieldsTest.php
* ./vendor/bin/phpunit ./vendor/goldenscarab/modulus-service-field/tests/Fields2Test.php
*/
class FieldsTest extends TestCase
{
private $data_source = [
'type' => [
'id' => 'mon-id',
'label' => 'mon-label',
'code' => 'mon-code'
]
];
private $options = [
1 => 'Option 1',
2 => 'Option 2',
......@@ -38,7 +30,7 @@ class FieldsTest extends TestCase
['id' => 4, 'title' => 'Titre 4', 'value' => 'value-4', 'data' => ['data1' => 'data-value4.1', 'data2' => 'data-value4.2']]
];
private $lorem = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Laboriosam, rem esse itaque inventore provident reiciendis quo, asperiores dolorem voluptate nostrum quisquam similique commodi quam consequatur ad eligendi iusto aperiam quos?';
private $lorem = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Laboriosam, rem esse itaque inventore provident reiciendis quo, asperiores dolorem voluptate nostrum quisquam similique commodi quam consequatur ad eligendi iusto aperiam quos?' . PHP_EOL . 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Laboriosam, rem esse itaque inventore provident reiciendis quo, asperiores dolorem voluptate nostrum quisquam similique commodi quam consequatur ad eligendi iusto aperiam quos?';
......@@ -54,7 +46,6 @@ class FieldsTest extends TestCase
public function testInputField()
{
$generated_string = Field::input([
'type' => 'text',
'label' => 'Total',
'name' => 'total',
'value' => 23.4,
......@@ -68,42 +59,28 @@ class FieldsTest extends TestCase
public function testInputAdvancedField()
{
$generated_string = Field::input([
'id' => 'total-final',
'type' => 'text',
'label' => 'Total',
'name' => 'total',
'value' => 23.4,
'class' => 'text-danger',
'prefix' => '<i class="fa fa-money"></i>',
'suffix' => '€',
'placeholder' => "123,30",
'help' => 'Taxe comprise',
'indice' => 1,
'style' => 'background-color: #c3c3c3;',
'indice' => 1,
'inline' => true,
'attributes' => [
'onchange' => 'console.log("change")',
'title' => [
'source' => $this->data_source,
'template' => '%s ~ %s',
'attributes' => ['type.id', 'type.label'],
'callback' => 'ucfirst'
]
'id' => 'total-final',
'type' => 'text',
'class' => 'text-danger',
'placeholder' => '123,30',
'onchange' => "console.log('change')",
'style' => 'background-color: #c3c3c3;',
'data-type' => 'column',
'disabled' => true,
'readonly' => true,
'required' => true,
'autocomplete' => true,
'autofocus' => true
],
'datas' => [
'type' => 'column',
'reference' => [
'source' => $this->data_source,
'template' => '%s|%s',
'attributes' => ['type.id', 'type.code'],
'callback' => 'ucfirst'
]
],
'is_inline' => true,
'is_disabled' => true,
'is_readonly' => true,
'is_required' => true,
'is_autocomplete' => true,
'is_autofocus' => true,
'popover' => [
'placement' => 'right',
'title' => 'Information',
......@@ -122,13 +99,7 @@ class FieldsTest extends TestCase
'label' => 'Collection',
'name' => 'collection',
'value' => 4,
'class' => 'select2',
'prefix' => '<i class="fa fa-list"></i>',
'suffix' => '<i class="fa fa-hand-paper-o"></i>',
'size' => 'sm',
'indice' => 34,
'is_required' => true,
'options' => $this->options
'options' => ['source' => $this->options]
]);
$desired_string = File::get(__DIR__ . '/html/fields/select_simple.html');
......@@ -142,20 +113,24 @@ class FieldsTest extends TestCase
'label' => 'Menu déroulant',
'name' => 'my_field_name',
'value' => 23,
'placeholder' => 'Choisir ...',
'size' => 'sm',
'is_required' => true,
'size' => 'sm',
'attributes' => [
'required' => true
],
'options' => [
'Groupe 1' => [
23 => 'Élement 23',
24 => 'Élement 24',
25 => 'Élement 25',
],
'Groupe 2' => [
26 => 'Élement 26',
27 => 'Élement 27',
28 => 'Élement 28',
]
'default' => ['value' => '', 'label' => 'Choisir...'],
'source' => [
'Groupe 1' => [
23 => 'Élement 23',
24 => 'Élement 24',
25 => 'Élement 25',
],
'Groupe 2' => [
26 => 'Élement 26',
27 => 'Élement 27',
28 => 'Élement 28',
]
]
]
]);
......@@ -169,19 +144,26 @@ class FieldsTest extends TestCase
$generated_string = Field::select([
'label' => 'Collection',
'name' => 'collection',
'values' => [2, 4],
'value' => [2, 4],
'class' => 'select2',
'prefix' => '<i class="fa fa-list"></i>',
'suffix' => '<i class="fa fa-hand-paper-o"></i>',
'indice' => 34,
'is_required' => true,
'is_multiple' => true,
'indice' => 34,
'attributes' => [
'class' => 'select2',
'multiple' => true,
'required' => true
],
'options' => [
'collect' => $this->collection,
'value' => 'id',
'template' => '%s - %s',
'callback' => 'strtoupper',
'text' => ['title', 'value'],
'source' => $this->collection,
'value' => ':id',
'label' => ['callback' => [
'function' => 'strtoupper',
'args' => ['template' => [
'format' => '%s - %s',
'args' => [':title', ':value']
]]
]],
]
]);
......@@ -198,13 +180,16 @@ class FieldsTest extends TestCase
'value' => 2,
'placeholder' => "Choisir...",
'options' => [
'collect' => $this->collection,
'value' => 'id',
'text' => ['title', 'value'],
'template' => '%s - %s',
'datas' => [
'data1' => 'data.data1',
'data2' => 'data.data2',
'source' => $this->collection,
'default' => ['value' => '', 'label' => 'Choisir...'],
'value' => ':id',
'label' => ['template' => [
'format' => '%s - %s',
'args' => [':title', ':value']
]],
'attributes' => [
'data-data1' => ':data.data1',
'data-data2' => ':data.data2',
]
]
]);
......@@ -220,8 +205,10 @@ class FieldsTest extends TestCase
'label' => 'Contenu',
'name' => 'content',
'value' => $this->lorem,
'class' => 'text-editor',
'rows' => 15,
'attributes' => [
'class' => 'text-editor',
'rows' => 15,
],
'popover' => [
'placement' => 'right',
'title' => 'Le contenu',
......@@ -234,13 +221,186 @@ class FieldsTest extends TestCase
$this->assertEquals($desired_string, $generated_string);
}
public function testRangeField()
{
$generated_string = Field::range([
'label' => 'Zoom',
'name' => 'zoom',
'value' => 7,
'attributes' => [
'min' => -10,
'max' => 10,
],
]);
$desired_string = File::get(__DIR__ . '/html/fields/range.html');
$this->assertEquals($desired_string, $generated_string);
}
public function testCheckboxField()
{
$generated_string = Field::checkbox([
'label' => 'Choix multiple',
'name' => 'my_field_name',
'value' => [2, 3],
'inline' => true,
'options' => ['source' => $this->options]
]);
$desired_string = File::get(__DIR__ . '/html/fields/checkbox.html');
$this->assertEquals($desired_string, $generated_string);
}
public function testCheckboxIndiceField()
{
$generated_string = Field::checkbox([
'label' => 'Choix multiple',
'name' => 'my_field_name',
'indice' => 12,
'values' => [2, 3],
'inline' => true,
'options' => ['source' => $this->options]
]);
$desired_string = File::get(__DIR__ . '/html/fields/checkbox_indice.html');
$this->assertEquals($desired_string, $generated_string);
}
public function testCheckboxCollectField()
{
$generated_string = Field::checkbox([
'label' => 'Mon Champs',
'name' => 'mon-champs',
'value' => ['value-2', 'value-3'],
'options' => [
'source' => $this->collection,
'value' => ':id',
'label' => ['callback' => [
'function' => 'strtoupper',
'args' => ['template' => [
'format' => '%s - %s',
'args' => [':title', ':value']
]]
]],
'attributes' => [
'data-one' => ':data.data1',
'data-two' => ':data.data2',
'class' => [
'condition' => [
'value' => ':id',
'operator' => '==',
'comparator' => 2,
'true' => 'my-class-id-2',
]
]
]
]
]);
$desired_string = File::get(__DIR__ . '/html/fields/checkbox_collect.html');
$this->assertEquals($desired_string, $generated_string);
}
public function testRadioField()
{
$generated_string = Field::radio([
'label' => 'Choix',
'name' => 'my_field_name',
'value' => 2,
'inline' => true,
'options' => ['source' => $this->options]
]);
$desired_string = File::get(__DIR__ . '/html/fields/radio.html');
$this->assertEquals($desired_string, $generated_string);
}
public function testRadioIndiceField()
{
$generated_string = Field::radio([
'label' => 'Choix',
'name' => 'my_field_name',
'indice' => true,
'values' => 2, 3,
'inline' => true,
'options' => ['source' => $this->options]
]);
$desired_string = File::get(__DIR__ . '/html/fields/radio_indice_true.html');
$this->assertEquals($desired_string, $generated_string);
}
public function testRadioCollectField()
{
$generated_string = Field::radio([
'label' => 'Mon Champs',
'name' => 'mon-champs',
'value' => 'value-2',
'options' => [
'source' => $this->collection,
'value' => ':id',
'label' => ['callback' => [
'function' => 'strtoupper',
'args' => ['template' => [
'format' => '%s - %s',
'args' => [':title', ':value']
]]
]],
'attributes' => [
'data-one' => ':data.data1',
'data-two' => ':data.data2',
'class' => [
'condition' => [
'value' => ':id',
'operator' => '==',
'comparator' => 2,
'true' => 'my-class-id-2',
]
]
]
]
]);
$desired_string = File::get(__DIR__ . '/html/fields/radio_collect.html');
$this->assertEquals($desired_string, $generated_string);
}
public function testToggleField()
{
$generated_string = Field::toggle([
'label' => 'Toggle',
'name' => 'toggle',
'value' => 1,
'attributes' => [
'data-on' => 'Actif',
'data-off' => 'Inactif',
'data-onstyle' => 'success',
'data-offstyle' => 'danger',
'data-toggle' => 'toggle',
'data-width' => '75',
'data-size' => 'xs'
]
]);
$desired_string = File::get(__DIR__ . '/html/fields/toggle.html');
$this->assertEquals($desired_string, $generated_string);
}
public function testFileField()
{
$generated_string = Field::file([
'label' => 'Uploader',
'name' => 'csv',
'prefix' => 'Fichier',
'placeholder' => 'Aucun fichier choisi'
'attributes' => ['placeholder' => 'Aucun fichier choisi']
]);
$desired_string = File::get(__DIR__ . '/html/fields/file.html');
......@@ -254,9 +414,12 @@ class FieldsTest extends TestCase
'label' => 'Champs pdf',
'name' => 'my_field_pdf',
'value' => 'test.pdf',
'placeholder' => 'ex: /upload/folder/file.pdf',
'suffix' => '<i class="fa fa-file-pdf-o mr-2"></i> Choisir un PDF',
'is_required' => true,
'suffix' => '<i class="fa fa-file-pdf-o mr-2"></i> Choisir un PDF',
'attributes' => [
'placeholder' => 'ex: /upload/folder/file.pdf',
'required' => true,
]
]);
$desired_string = File::get(__DIR__ . '/html/fields/pdf.html');
......@@ -266,13 +429,15 @@ class FieldsTest extends TestCase
public function testVideoField()
{
$generated_string = Field::pdf([
$generated_string = Field::video([
'label' => 'Champs video',
'name' => 'my_field_video',
'value' => 'my-video.mp4',
'placeholder' => 'ex: /upload/folder/video.mp4',
'suffix' => '<i class="fa fa-file-video-o mr-2"></i> Choisir une vidéo',
'is_required' => true,
'attributes' => [
'placeholder' => 'ex: /upload/folder/video.mp4',
'required' => true,
]
]);
$desired_string = File::get(__DIR__ . '/html/fields/video.html');
......@@ -282,13 +447,15 @@ class FieldsTest extends TestCase
public function testImageField()
{
$generated_string = Field::pdf([
$generated_string = Field::image([
'label' => 'Champs image',
'name' => 'my_field_image',
'value' => 'image.png',
'placeholder' => 'ex: /upload/folder/image.png',
'suffix' => '<i class="fa fa-file-image-o mr-2"></i> Choisir une image',
'is_required' => true,
'attributes' => [
'placeholder' => 'ex: /upload/folder/image.png',
'required' => true,
]
]);
$desired_string = File::get(__DIR__ . '/html/fields/image.html');
......@@ -296,43 +463,6 @@ class FieldsTest extends TestCase
$this->assertEquals($desired_string, $generated_string);
}
public function testToogleField()
{
$generated_string = Field::toggle([
'label' => 'Toggle',
'name' => 'toggle',
'value' => 1,
'datas' => [
'on' => 'Actif',
'off' => 'Inactif',
'onstyle' => 'success',
'offstyle' => 'danger',
'toggle' => 'toggle',
'width' => '75',
'size' => 'xs'
]
]);
$desired_string = File::get(__DIR__ . '/html/fields/toggle.html');
$this->assertEquals($desired_string, $generated_string);
}
public function testRangeField()
{
$generated_string = Field::range([
'label' => 'Zoom',
'name' => 'zoom',
'min' => 0,
'max' => 20,
'value' => 7
]);
$desired_string = File::get(__DIR__ . '/html/fields/range.html');
$this->assertEquals($desired_string, $generated_string);
}
public function testCodeField()
{
$generated_string = Field::code([
......@@ -356,116 +486,7 @@ class FieldsTest extends TestCase
$this->assertEquals($desired_string, $generated_string);
}
public function testRadioField()
{
$generated_string = Field::radio([
'label' => 'Choix unique',
'name' => 'my_field_name',
'value' => 2,
'is_inline' => true,
'options' => $this->options
]);
$desired_string = File::get(__DIR__ . '/html/fields/radio.html');
$this->assertEquals($desired_string, $generated_string);
}
public function testRadioIndiceTrueField()
{
$generated_string = Field::radio([
'label' => 'Choix unique',
'name' => 'my_field_name',
'value' => 2,
'indice' => true,
'is_inline' => true,
'options' => $this->options
]);
$desired_string = File::get(__DIR__ . '/html/fields/radio_indice_true.html');
$this->assertEquals($desired_string, $generated_string);
}
public function testRadioCollectField()
{
$generated_string = Field::radio([
'label' => 'Mon Champs',
'name' => 'mon-champs',
'value' => 'value-2',
'is_inline' => false,
'options' => [
'collect' => $this->collection,
'value' => 'value',
'template' => '%s - %s',
'text' => ['id', 'title'],
'callback' => 'strtoupper',
'datas' => [
'one' => 'data.data1',
'tow' => 'data.data2',
]
]
]);
$desired_string = File::get(__DIR__ . '/html/fields/radio_collect.html');
$this->assertEquals($desired_string, $generated_string);
}
public function testCheckboxField()
{
$generated_string = Field::checkbox([
'label' => 'Choix multiple',
'name' => 'my_field_name',
'values' => [2, 3],
'is_inline' => true,
'options' => $this->options
]);
$desired_string = File::get(__DIR__ . '/html/fields/checkbox.html');
$this->assertEquals($desired_string, $generated_string);
}
public function testCheckboxIndiceField()
{
$generated_string = Field::checkbox([
'label' => 'Choix multiple',
'name' => 'my_field_name',
'indice' => 12,
'values' => [2, 3],
'is_inline' => true,
'options' => $this->options
]);
$desired_string = File::get(__DIR__ . '/html/fields/checkbox_indice.html');
$this->assertEquals($desired_string, $generated_string);
}
public function testCheckboxCollectField()
{
$generated_string = Field::checkbox([
'label' => 'Mon Champs',
'name' => 'mon-champs',
'values' => ['value-2', 'value-3'],
'is_inline' => false,
'options' => [
'collect' => $this->collection,
'value' => 'value',
'template' => '%s - %s',
'text' => ['id', 'title'],
'callback' => 'strtoupper',
'datas' => [
'one' => 'data.data1',
'tow' => 'data.data2',
]
]
]);
$desired_string = File::get(__DIR__ . '/html/fields/checkbox_collect.html');
$this->assertEquals($desired_string, $generated_string);
}
}
<div class="form-group row">
<label for="my-field-name-5" class="col-sm-2">Choix multiple</label>
<label class="col-sm-2">Choix multiple</label>
<div class="col-sm-10">
<div class="form-check form-check-inline">
<input type="checkbox" id="my-field-name-1" class="form-check-input" name="my_field_name[]" value="1"/>
<label class="form-check-label" for="my-field-name-1">Option 1</label>
<input id="field-my-field-name-1" name="my_field_name[]" value="1" class="form-check-input" type="checkbox"/>
<label class="form-check-label" for="field-my-field-name-1">Option 1</label>
</div>
<div class="form-check form-check-inline">
<input type="checkbox" id="my-field-name-2" class="form-check-input" name="my_field_name[]" value="2" checked/>
<label class="form-check-label" for="my-field-name-2">Option 2</label>
<input id="field-my-field-name-2" name="my_field_name[]" value="2" class="form-check-input" type="checkbox" checked/>
<label class="form-check-label" for="field-my-field-name-2">Option 2</label>
</div>
<div class="form-check form-check-inline">
<input type="checkbox" id="my-field-name-3" class="form-check-input" name="my_field_name[]" value="3" checked/>
<label class="form-check-label" for="my-field-name-3">Option 3</label>
<input id="field-my-field-name-3" name="my_field_name[]" value="3" class="form-check-input" type="checkbox" checked/>
<label class="form-check-label" for="field-my-field-name-3">Option 3</label>
</div>
<div class="form-check form-check-inline">
<input type="checkbox" id="my-field-name-4" class="form-check-input" name="my_field_name[]" value="4"/>
<label class="form-check-label" for="my-field-name-4">Option 4</label>
<input id="field-my-field-name-4" name="my_field_name[]" value="4" class="form-check-input" type="checkbox"/>
<label class="form-check-label" for="field-my-field-name-4">Option 4</label>
</div>
<div class="form-check form-check-inline">
<input type="checkbox" id="my-field-name-5" class="form-check-input" name="my_field_name[]" value="5"/>
<label class="form-check-label" for="my-field-name-5">Option 5</label>
<input id="field-my-field-name-5" name="my_field_name[]" value="5" class="form-check-input" type="checkbox"/>
<label class="form-check-label" for="field-my-field-name-5">Option 5</label>
</div>
</div>
</div>
<div class="form-group">
<label for="mon-champs-value-4">Mon Champs</label>
<label>Mon Champs</label>
<div class="form-check">
<input type="checkbox" id="mon-champs-value-1" class="form-check-input" name="mon-champs[]" value="VALUE-1" data-one="data-value1.1" data-tow="data-value1.2" />
<label class="form-check-label" for="mon-champs-value-1">1 - TITRE 1</label>
<input id="field-mon-champs-1" name="mon-champs[]" value="1" data-one="data-value1.1" data-two="data-value1.2" class="form-check-input" type="checkbox"/>
<label class="form-check-label" for="field-mon-champs-1">TITRE 1 - VALUE-1</label>
</div>
<div class="form-check">
<input type="checkbox" id="mon-champs-value-2" class="form-check-input" name="mon-champs[]" value="VALUE-2" data-one="data-value2.1" data-tow="data-value2.2" />
<label class="form-check-label" for="mon-champs-value-2">2 - TITRE 2</label>
<input id="field-mon-champs-2" name="mon-champs[]" value="2" data-one="data-value2.1" data-two="data-value2.2" class="my-class-id-2 form-check-input" type="checkbox"/>
<label class="form-check-label" for="field-mon-champs-2">TITRE 2 - VALUE-2</label>
</div>
<div class="form-check">
<input type="checkbox" id="mon-champs-value-3" class="form-check-input" name="mon-champs[]" value="VALUE-3" data-one="data-value3.1" data-tow="data-value3.2" />
<label class="form-check-label" for="mon-champs-value-3">3 - TITRE 3</label>
<input id="field-mon-champs-3" name="mon-champs[]" value="3" data-one="data-value3.1" data-two="data-value3.2" class="form-check-input" type="checkbox"/>
<label class="form-check-label" for="field-mon-champs-3">TITRE 3 - VALUE-3</label>
</div>
<div class="form-check">
<input type="checkbox" id="mon-champs-value-4" class="form-check-input" name="mon-champs[]" value="VALUE-4" data-one="data-value4.1" data-tow="data-value4.2" />
<label class="form-check-label" for="mon-champs-value-4">4 - TITRE 4</label>
<input id="field-mon-champs-4" name="mon-champs[]" value="4" data-one="data-value4.1" data-two="data-value4.2" class="form-check-input" type="checkbox"/>
<label class="form-check-label" for="field-mon-champs-4">TITRE 4 - VALUE-4</label>
</div>
</div>
<div class="form-group row">
<label for="my-field-name-12-5" class="col-sm-2">Choix multiple</label>
<label class="col-sm-2">Choix multiple</label>
<div class="col-sm-10">
<div class="form-check form-check-inline">
<input type="checkbox" id="my-field-name-12-1" class="form-check-input" name="my_field_name[12][]" value="1"/>
<label class="form-check-label" for="my-field-name-12-1">Option 1</label>
<input id="field-my-field-name-12-1" name="my_field_name[12][]" value="1" class="form-check-input" type="checkbox"/>
<label class="form-check-label" for="field-my-field-name-12-1">Option 1</label>
</div>
<div class="form-check form-check-inline">
<input type="checkbox" id="my-field-name-12-2" class="form-check-input" name="my_field_name[12][]" value="2" checked/>
<label class="form-check-label" for="my-field-name-12-2">Option 2</label>
<input id="field-my-field-name-12-2" name="my_field_name[12][]" value="2" class="form-check-input" type="checkbox"/>
<label class="form-check-label" for="field-my-field-name-12-2">Option 2</label>
</div>
<div class="form-check form-check-inline">
<input type="checkbox" id="my-field-name-12-3" class="form-check-input" name="my_field_name[12][]" value="3" checked/>
<label class="form-check-label" for="my-field-name-12-3">Option 3</label>
<input id="field-my-field-name-12-3" name="my_field_name[12][]" value="3" class="form-check-input" type="checkbox"/>
<label class="form-check-label" for="field-my-field-name-12-3">Option 3</label>
</div>
<div class="form-check form-check-inline">
<input type="checkbox" id="my-field-name-12-4" class="form-check-input" name="my_field_name[12][]" value="4"/>
<label class="form-check-label" for="my-field-name-12-4">Option 4</label>
<input id="field-my-field-name-12-4" name="my_field_name[12][]" value="4" class="form-check-input" type="checkbox"/>
<label class="form-check-label" for="field-my-field-name-12-4">Option 4</label>
</div>
<div class="form-check form-check-inline">
<input type="checkbox" id="my-field-name-12-5" class="form-check-input" name="my_field_name[12][]" value="5"/>
<label class="form-check-label" for="my-field-name-12-5">Option 5</label>
<input id="field-my-field-name-12-5" name="my_field_name[12][]" value="5" class="form-check-input" type="checkbox"/>
<label class="form-check-label" for="field-my-field-name-12-5">Option 5</label>
</div>
</div>
</div>
<div class="form-group">
<label for="field-content" class="required">Contenu</label>
<div id="editor-field-content" class="code-editor"style="min-height: 400px;" data-language="javascript" data-readonly="false" data-beautiful="false" data-target="#field-content">function foo(items) {
<label>Contenu</label>
<div id="editor-field-content" class="code-editor" data-target="#field-content" style="min-height: 300px;" data-language="html">function foo(items) {
var x = &quot;All this is syntax highlighted&quot;;
return x;
}</div>
......
......@@ -5,7 +5,7 @@
<div class="input-group-text">Fichier</div>
</div>
<div class="custom-file">
<input type="file" id="field-csv" class="custom-file-input" name="csv" value="" placeholder="Aucun fichier choisi" />
<input id="field-csv" class="custom-file-input" type="file" name="csv" placeholder="Aucun fichier choisi" />
<label class="custom-file-label" for="field-csv">Aucun fichier choisi</label>
<script type="text/javascript">
document.getElementById('field-csv').addEventListener('change', function(e) {
......
<div class="form-group">
<label for="field-my-field-image" class="required">Champs image</label>
<div class="input-group">
<div class="input-group img-group">
<div class="input-group-prepend">
<div class="input-group-text text-danger">
<i class="fa fa-file-pdf-o" aria-hidden="true"></i>
</div>
<img id="thumb-field-my-field-image" class="image-thumb" src="http://localhost:8000/image.png" alt="thumb">
</div>
<input type="text" id="field-my-field-image" class="form-control" name="my_field_image" value="image.png" placeholder="ex: /upload/folder/image.png" required="required" />
<input id="field-my-field-image" class="form-control" type="text" name="my_field_image" value="image.png" placeholder="ex: /upload/folder/image.png" required />
<div class="input-group-append">
<button class="btn btn-outline-secondary popupfinder" type="button" id="btn-field-my-field-image" data-field="#field-my-field-image" data-mimes="application/pdf">
<button class="btn btn-outline-secondary popupfinder" type="button" id="btn-field-my-field-image" data-thumb="#thumb-field-my-field-image" data-field="#field-my-field-image" data-mimes="image">
<i class="fa fa-file-image-o mr-2"></i> Choisir une image
</button>
</div>
......
<div class="form-group">
<label for="field-total">Total</label>
<input type="text" id="field-total" class="form-control" name="total" value="23,4" />
<input id="field-total" class="form-control" type="text" name="total" value="23,4" />
</div>
<div class="form-group row">
<label for="total-final-1" class="requiredcol-sm-2">Total</label>
<label for="total-final" class="required col-sm-2">Total</label>
<span class="text-info popup-help" data-toggle="popover" data-placement="right" title="Information" data-content="Le montant est calculé selon les éléments communiqué. Il peux néanmoins variée suivant d'autre facteurs non pris en compte">
<i class="fa fa-info-circle"></i>
</span>
......@@ -8,7 +8,7 @@
<div class="input-group-prepend">
<div class="input-group-text"><i class="fa fa-money"></i></div>
</div>
<input type="text" id="total-final-1" class="form-control text-danger" name="total[1]" value="23,4" placeholder="123,30" style="background-color: #c3c3c3;" autocomplete="autocomplete" autofocus="autofocus" disabled="disabled" required="required" readonly="readonly" onchange="console.log("change")" title="Mon-id ~ mon-label" data-type="column" data-reference="Mon-id|mon-code" />
<input id="total-final" class="form-control text-danger" type="text" name="total[1]" value="23,4" placeholder="123,30" onchange="console.log('change')" style="background-color: #c3c3c3;" data-type="column" disabled readonly required autocomplete autofocus />
<div class="input-group-append">
<div class="input-group-text"></div>
</div>
......
......@@ -2,11 +2,11 @@
<label for="field-my-field-pdf" class="required">Champs pdf</label>
<div class="input-group">
<div class="input-group-prepend">
<div class="input-group-text text-danger">
<i class="fa fa-file-pdf-o" aria-hidden="true"></i>
<div class="input-group-text">
<i class="fa fa-file-pdf-o text-danger"></i>
</div>
</div>
<input type="text" id="field-my-field-pdf" class="form-control" name="my_field_pdf" value="test.pdf" placeholder="ex: /upload/folder/file.pdf" required="required" />
<input id="field-my-field-pdf" class="form-control" type="text" name="my_field_pdf" value="test.pdf" placeholder="ex: /upload/folder/file.pdf" required />
<div class="input-group-append">
<button class="btn btn-outline-secondary popupfinder" type="button" id="btn-field-my-field-pdf" data-field="#field-my-field-pdf" data-mimes="application/pdf">
<i class="fa fa-file-pdf-o mr-2"></i> Choisir un PDF
......
<div class="form-group row">
<label for="my-field-name-5" class="col-sm-2">Choix unique</label>
<label class="col-sm-2">Choix</label>
<div class="col-sm-10">
<div class="form-check form-check-inline">
<input type="radio" id="my-field-name-1" class="form-check-input" name="my_field_name" value="1"/>
<label class="form-check-label" for="my-field-name-1">Option 1</label>
<input id="field-my-field-name-1" name="my_field_name" value="1" class="form-check-input" type="radio"/>
<label class="form-check-label" for="field-my-field-name-1">Option 1</label>
</div>
<div class="form-check form-check-inline">
<input type="radio" id="my-field-name-2" class="form-check-input" name="my_field_name" value="2" checked/>
<label class="form-check-label" for="my-field-name-2">Option 2</label>
<input id="field-my-field-name-2" name="my_field_name" value="2" class="form-check-input" type="radio" checked/>
<label class="form-check-label" for="field-my-field-name-2">Option 2</label>
</div>
<div class="form-check form-check-inline">
<input type="radio" id="my-field-name-3" class="form-check-input" name="my_field_name" value="3"/>
<label class="form-check-label" for="my-field-name-3">Option 3</label>
<input id="field-my-field-name-3" name="my_field_name" value="3" class="form-check-input" type="radio"/>
<label class="form-check-label" for="field-my-field-name-3">Option 3</label>
</div>
<div class="form-check form-check-inline">
<input type="radio" id="my-field-name-4" class="form-check-input" name="my_field_name" value="4"/>
<label class="form-check-label" for="my-field-name-4">Option 4</label>
<input id="field-my-field-name-4" name="my_field_name" value="4" class="form-check-input" type="radio"/>
<label class="form-check-label" for="field-my-field-name-4">Option 4</label>
</div>
<div class="form-check form-check-inline">
<input type="radio" id="my-field-name-5" class="form-check-input" name="my_field_name" value="5"/>
<label class="form-check-label" for="my-field-name-5">Option 5</label>
<input id="field-my-field-name-5" name="my_field_name" value="5" class="form-check-input" type="radio"/>
<label class="form-check-label" for="field-my-field-name-5">Option 5</label>
</div>
</div>
</div>
<div class="form-group">
<label for="mon-champs-value-4">Mon Champs</label>
<label>Mon Champs</label>
<div class="form-check">
<input type="radio" id="mon-champs-value-1" class="form-check-input" name="mon-champs" value="VALUE-1" data-one="data-value1.1" data-tow="data-value1.2" />
<label class="form-check-label" for="mon-champs-value-1">1 - TITRE 1</label>
<input id="field-mon-champs-1" name="mon-champs" value="1" data-one="data-value1.1" data-two="data-value1.2" class="form-check-input" type="radio"/>
<label class="form-check-label" for="field-mon-champs-1">TITRE 1 - VALUE-1</label>
</div>
<div class="form-check">
<input type="radio" id="mon-champs-value-2" class="form-check-input" name="mon-champs" value="VALUE-2" data-one="data-value2.1" data-tow="data-value2.2" />
<label class="form-check-label" for="mon-champs-value-2">2 - TITRE 2</label>
<input id="field-mon-champs-2" name="mon-champs" value="2" data-one="data-value2.1" data-two="data-value2.2" class="my-class-id-2 form-check-input" type="radio"/>
<label class="form-check-label" for="field-mon-champs-2">TITRE 2 - VALUE-2</label>
</div>
<div class="form-check">
<input type="radio" id="mon-champs-value-3" class="form-check-input" name="mon-champs" value="VALUE-3" data-one="data-value3.1" data-tow="data-value3.2" />
<label class="form-check-label" for="mon-champs-value-3">3 - TITRE 3</label>
<input id="field-mon-champs-3" name="mon-champs" value="3" data-one="data-value3.1" data-two="data-value3.2" class="form-check-input" type="radio"/>
<label class="form-check-label" for="field-mon-champs-3">TITRE 3 - VALUE-3</label>
</div>
<div class="form-check">
<input type="radio" id="mon-champs-value-4" class="form-check-input" name="mon-champs" value="VALUE-4" data-one="data-value4.1" data-tow="data-value4.2" />
<label class="form-check-label" for="mon-champs-value-4">4 - TITRE 4</label>
<input id="field-mon-champs-4" name="mon-champs" value="4" data-one="data-value4.1" data-two="data-value4.2" class="form-check-input" type="radio"/>
<label class="form-check-label" for="field-mon-champs-4">TITRE 4 - VALUE-4</label>
</div>
</div>
<div class="form-group row">
<label for="my-field-name-5" class="col-sm-2">Choix unique</label>
<label class="col-sm-2">Choix</label>
<div class="col-sm-10">
<div class="form-check form-check-inline">
<input type="radio" id="my-field-name-1" class="form-check-input" name="my_field_name[]" value="1"/>
<label class="form-check-label" for="my-field-name-1">Option 1</label>
<input id="field-my-field-name-1" name="my_field_name[]" value="1" class="form-check-input" type="radio"/>
<label class="form-check-label" for="field-my-field-name-1">Option 1</label>
</div>
<div class="form-check form-check-inline">
<input type="radio" id="my-field-name-2" class="form-check-input" name="my_field_name[]" value="2" checked/>
<label class="form-check-label" for="my-field-name-2">Option 2</label>
<input id="field-my-field-name-2" name="my_field_name[]" value="2" class="form-check-input" type="radio"/>
<label class="form-check-label" for="field-my-field-name-2">Option 2</label>
</div>
<div class="form-check form-check-inline">
<input type="radio" id="my-field-name-3" class="form-check-input" name="my_field_name[]" value="3"/>
<label class="form-check-label" for="my-field-name-3">Option 3</label>
<input id="field-my-field-name-3" name="my_field_name[]" value="3" class="form-check-input" type="radio"/>
<label class="form-check-label" for="field-my-field-name-3">Option 3</label>
</div>
<div class="form-check form-check-inline">
<input type="radio" id="my-field-name-4" class="form-check-input" name="my_field_name[]" value="4"/>
<label class="form-check-label" for="my-field-name-4">Option 4</label>
<input id="field-my-field-name-4" name="my_field_name[]" value="4" class="form-check-input" type="radio"/>
<label class="form-check-label" for="field-my-field-name-4">Option 4</label>
</div>
<div class="form-check form-check-inline">
<input type="radio" id="my-field-name-5" class="form-check-input" name="my_field_name[]" value="5"/>
<label class="form-check-label" for="my-field-name-5">Option 5</label>
<input id="field-my-field-name-5" name="my_field_name[]" value="5" class="form-check-input" type="radio"/>
<label class="form-check-label" for="field-my-field-name-5">Option 5</label>
</div>
</div>
</div>
<div class="form-group">
<label for="field-zoom">Zoom</label>
<input type="range" id="field-zoom" class="form-control" name="zoom" value="7" max="20" oninput="zoomShowValue(this.value)" />
<input id="field-zoom" class="form-control" type="range" name="zoom" value="7" min="-10" max="10" oninput="zoomShowValue(this.value)" />
<span id="field-zoom-value">7&nbsp;</span>
<script type="text/javascript">
function zoomShowValue(newValue) {
......
<div class="form-group">
<label for="field-city-id">Ville</label>
<select id="field-city-id" class="form-control" name="city_id">
<option value="" selected >Choisir...</option>
<option value="">Choisir...</option>
<option value="1" data-data1="data-value1.1" data-data2="data-value1.2">Titre 1 - value-1</option>
<option value="2" data-data1="data-value2.1" data-data2="data-value2.2" selected>Titre 2 - value-2</option>
<option value="3" data-data1="data-value3.1" data-data2="data-value3.2">Titre 3 - value-3</option>
......
<div class="form-group">
<label for="field-my-field-name" class="required">Menu déroulant</label>
<select id="field-my-field-name" class="form-control form-control-sm" name="my_field_name" required="required">
<option value="" disabled hidden selected >Choisir ...</option>
<optgroup label="Groupe 1"><option value="23" selected>Élement 23</option>
<option value="24">Élement 24</option>
<option value="25">Élement 25</option>
<select id="field-my-field-name" class="form-control form-control-sm" name="my_field_name" required>
<option value="" disabled hidden>Choisir...</option>
<optgroup label="Groupe 1">
<option value="23" selected>Élement 23</option>
<option value="24">Élement 24</option>
<option value="25">Élement 25</option>
</optgroup>
<optgroup label="Groupe 2"><option value="26">Élement 26</option>
<option value="27">Élement 27</option>
<option value="28">Élement 28</option>
<optgroup label="Groupe 2">
<option value="26">Élement 26</option>
<option value="27">Élement 27</option>
<option value="28">Élement 28</option>
</optgroup>
</select>
</div>
......@@ -4,7 +4,7 @@
<div class="input-group-prepend">
<div class="input-group-text"><i class="fa fa-list"></i></div>
</div>
<select id="field-collection-34" class="form-control select2" name="collection[34][]" multiple="multiple" required="required">
<select id="field-collection-34" class="form-control select2" name="collection[34][]" multiple required>
<option value="1">TITRE 1 - VALUE-1</option>
<option value="2" selected>TITRE 2 - VALUE-2</option>
<option value="3">TITRE 3 - VALUE-3</option>
......
<div class="form-group">
<label for="field-collection-34" class="required">Collection</label>
<div class="input-group input-group-sm">
<div class="input-group-prepend">
<div class="input-group-text"><i class="fa fa-list"></i></div>
</div>
<select id="field-collection-34" class="form-control select2" name="collection[34]" required="required">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
<option value="4" selected>Option 4</option>
<option value="5">Option 5</option>
</select>
<div class="input-group-append">
<div class="input-group-text"><i class="fa fa-hand-paper-o"></i></div>
</div>
</div>
<label for="field-collection">Collection</label>
<select id="field-collection" class="form-control" name="collection">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
<option value="4" selected>Option 4</option>
<option value="5">Option 5</option>
</select>
</div>
......@@ -3,5 +3,6 @@
<span class="text-info popup-help" data-toggle="popover" data-placement="right" title="Le contenu" data-content="Le contenu est le coeur de l'article. Grâce à l'éditeur vous pouvez formater le rendu selon votre goût.">
<i class="fa fa-info-circle"></i>
</span>
<textarea id="field-content" class="form-control text-editor" name="content" rows="15">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Laboriosam, rem esse itaque inventore provident reiciendis quo, asperiores dolorem voluptate nostrum quisquam similique commodi quam consequatur ad eligendi iusto aperiam quos?</textarea>
<textarea id="field-content" class="form-control text-editor" name="content" rows="15">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Laboriosam, rem esse itaque inventore provident reiciendis quo, asperiores dolorem voluptate nostrum quisquam similique commodi quam consequatur ad eligendi iusto aperiam quos?
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Laboriosam, rem esse itaque inventore provident reiciendis quo, asperiores dolorem voluptate nostrum quisquam similique commodi quam consequatur ad eligendi iusto aperiam quos?</textarea>
</div>
<div class="form-group">
<label for="field-toggle">Toggle</label>
<div class="toogle">
<input type="checkbox" value="1" id="field-toggle" class="form-control" name="toggle" data-on="Actif" data-off="Inactif" data-onstyle="success" data-offstyle="danger" data-toggle="toggle" data-width="75" data-size="xs" checked />
<input value="1" id="field-toggle" class="form-control" name="toggle" type="checkbox" checked data-on="Actif" data-off="Inactif" data-onstyle="success" data-offstyle="danger" data-toggle="toggle" data-width="75" data-size="xs" />
</div>
</div>
......@@ -2,13 +2,13 @@
<label for="field-my-field-video" class="required">Champs video</label>
<div class="input-group">
<div class="input-group-prepend">
<div class="input-group-text text-danger">
<i class="fa fa-file-pdf-o" aria-hidden="true"></i>
<div class="input-group-text">
<i class="fa fa-video-camera"></i>
</div>
</div>
<input type="text" id="field-my-field-video" class="form-control" name="my_field_video" value="my-video.mp4" placeholder="ex: /upload/folder/video.mp4" required="required" />
<input id="field-my-field-video" class="form-control" type="text" name="my_field_video" value="my-video.mp4" placeholder="ex: /upload/folder/video.mp4" required />
<div class="input-group-append">
<button class="btn btn-outline-secondary popupfinder" type="button" id="btn-field-my-field-video" data-field="#field-my-field-video" data-mimes="application/pdf">
<button class="btn btn-outline-secondary popupfinder" type="button" id="btn-field-my-field-video" data-field="#field-my-field-video" data-mimes="video">
<i class="fa fa-file-video-o mr-2"></i> Choisir une vidéo
</button>
</div>
......
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