Browse Source

Field toggle

tags/0.1
Guillaume 3 years ago
parent
commit
cc053b7bbe
2 changed files with 6 additions and 3 deletions
  1. +2
    -1
      Field/StatusField.php
  2. +4
    -2
      Resources/views/adminlte/crud/field/toggle.html.twig

+ 2
- 1
Field/StatusField.php View File

->setFormType(ChoiceType::class) ->setFormType(ChoiceType::class)
->setFormTypeOption('expanded', false) ->setFormTypeOption('expanded', false)
->setFormTypeOption('multiple', false) ->setFormTypeOption('multiple', false)
->setFormTypeOption('choices', ['En ligne' => 1, 'Hors ligne' => 0]);
->setFormTypeOption('choices', ['En ligne' => 1, 'Hors ligne' => 0])
->setCustomOption('toggle_label', 'En ligne');


$template = 'toggle.html.twig' ; $template = 'toggle.html.twig' ;
if(!$templateToggle) { if(!$templateToggle) {

+ 4
- 2
Resources/views/adminlte/crud/field/toggle.html.twig View File

{% set property_name = field.getProperty() %} {% set property_name = field.getProperty() %}
{% set id_toggle = 'toogle-'~item.id~'-'~property_name %} {% set id_toggle = 'toogle-'~item.id~'-'~property_name %}


<div class="custom-control custom-switch custom-switch-on-primary custom-switch-off-default" data-propertyname="{{ property_name }}" data-id={{ item.id }}>
<div class="custom-control custom-switch custom-switch-on-success custom-switch-off-default"
data-propertyname="{{ property_name }}" data-id={{ item.id }}>
<input type="checkbox" class="custom-control-input" id="{{ id_toggle }}" {{ field.value ? 'checked' }}> <input type="checkbox" class="custom-control-input" id="{{ id_toggle }}" {{ field.value ? 'checked' }}>
<label class="custom-control-label" for="{{ id_toggle }}">{{ field.label }}</label>
<label class="custom-control-label" for="{{ id_toggle }}">
{{ field.getCustomOption('toggle_label') ?? field.label }}</label>
</div> </div>

Loading…
Cancel
Save