templates/component/form/input.html.twig line 1

Open in your IDE?
  1. {#
  2.     component: input
  3. #}
  4. {% set props = {
  5.     type: 'text',
  6.     label: null,
  7.     placeholder: null,
  8.     pattern:null,
  9.     name: null,
  10.     id: null,
  11.     ref:null,
  12.     autocomplete: null,
  13.     min: null,
  14.     max: null,
  15.     value: null,
  16.     checked: false,
  17.     required: false,
  18.         selected:null,
  19.     max_chars:null
  20. }|merge(props|default({})) %}
  21. {# Add * after label if required #}
  22. {% set label = props.label %}
  23. {% if props.required and props.label %}
  24.     {% set label = label ~ '*' %}
  25. {% endif %}
  26. {#  #}
  27. {# Construct attributes #}
  28. {#  #}
  29. {% set attributes = 'ref=input name='~props.name %}
  30. {# Placeholder attribute #}
  31.     {% if props.placeholder %}
  32. {% set attributes = attributes ~ ' placeholder="' ~ props.placeholder ~ '"' %}
  33. {% endif %}
  34. {# required attribute #}
  35.     {% if props.required %}
  36. {% set attributes = attributes ~ ' required' %}
  37. {% endif %}
  38. {# checked attribute #}
  39.     {% if props.checked %}
  40. {% set attributes = attributes ~ ' checked' %}
  41. {% endif %}
  42. {# value attribute #}
  43.     {% if props.value %}
  44. {% set attributes = attributes ~ ' value="' ~ props.value ~ '"' %}
  45. {% endif %}
  46. {# ref attribute #}
  47.     {% if props.pattern %}
  48. {% set attributes = attributes ~ ' pattern="' ~ props.pattern ~ '"' %}
  49. {% endif %}
  50. {# autocomplete attribute #}
  51.     {% if props.autocomplete %}
  52. {% set attributes = attributes ~ ' autocomplete="' ~ props.autocomplete ~ '"' %}
  53. {% endif %}
  54. {# min attribute #}
  55.     {% if props.min %}
  56. {% set attributes = attributes ~ ' min="' ~ props.min ~ '"' %}
  57. {% endif %}
  58. {# max attribute #}
  59.     {% if props.max %}
  60. {% set attributes = attributes ~ ' max="' ~ props.max ~ '"' %}
  61. {% endif %}
  62. {# tel pattern #}
  63. {# Construct classes #}
  64. {% set classes = ['type' ~ props.type] %}
  65. {# Required #}
  66.     {% if props.required %}
  67. {% set classes = classes|merge(['is-required']) %}
  68. {% endif %}
  69.     <div
  70.     data-component="input" data-type="{{ props.type }}" class="Input-component {{ classes|join(' ') }}"> {# Label #}
  71.     <label class="Input-label" for="{{ props.id }}" ref="label">{{ label|raw }}</label>
  72.     {# Textarea #}
  73.     {% if props.type == 'textarea' %}
  74.         <textarea {{ attributes | raw }} id="{{ props.id }}" class="InputForm Input-textarea">{{ props.value }}</textarea>
  75.         {% if  props.max_chars %}
  76.             <p class="Input-textarea-limit">
  77.                 <span ref="counter">0</span>
  78.                 /
  79.                 <span ref="limit">
  80.                     {{ props.max_chars }}</span>
  81.             </p>
  82.         {% endif %}
  83.         {# Commons inputs #}
  84.     {% elseif props.type == 'text' or props.type == 'email' or props.type == 'tel' or props.type == "number" or props.type == "password" %}
  85.         <input {{ attributes | raw }} id="{{ props.id }}" type="{{ props.type }}" class="InputForm Input-input">
  86.         {% if props.type == 'password' %}
  87.             <div class="Input-passwordSee" ref="seeBtn">
  88.                 {% include "component/svg.html.twig" with {
  89.           props: {
  90.             name: 'view'
  91.           }
  92.         } %}
  93.             </div>
  94.             <div class="Input-passwordHide" ref="hideBtn">
  95.                 {% include "component/svg.html.twig" with {
  96.           props: {
  97.             name: 'edit'
  98.           }
  99.         } %}
  100.             </div>
  101.         {% endif %}
  102.         {# Date input #}
  103.     {% elseif props.type == 'date' %}
  104.         <div class="BaseInput-date">
  105.             <datepicker {{ attributes|raw }} :language="datePickerLang" data-lang="fr"></datepicker>
  106.         </div>
  107.         <span class="DateIcon">
  108.             {% include "component/svg.html.twig" with {
  109.           props: {
  110.             name: 'calendar'
  111.           }
  112.         } %}
  113.         </span>
  114.         {# checkbox #}
  115.     {% elseif props.type == 'checkbox' %}
  116.         <div class="BaseInput-checkbox">
  117.             <div class="BaseInput-checkboxCheck"></div>
  118.             <input {{ attributes|raw }} id="{{ props.id }}" type="checkbox">
  119.         </div>
  120.         {# Radio #}
  121.     {% elseif props.type == 'radio' %}
  122.         <div class="BaseInput-radio">
  123.             <div class="BaseInput-radioCheck"></div>
  124.             <input {{ attributes|raw }} id="{{ props.id }}" type="radio">
  125.         </div>
  126.         {# Select #}
  127.     {% elseif props.type == 'select' %}
  128.         <div class="BaseInput-select">
  129.             <v-select ref="input" id="{{ props.id }}" data-selected="{{ props.selected|json_encode() }}" :options="options" data-options="{{ props.options|json_encode() }}" v-model="selected" :searchable="false" :clearable="false" @input="onChange">
  130.                 {% verbatim %}
  131.                     <template #selected-option="{ label }">
  132.                         <span class="vs__selected-optionsLabel" v-html="label"/>
  133.                     </template>
  134.                     <template #search="{attributes, events}">
  135.                         <input class="vs__search" :required="!selected" v-bind="attributes" v-on="events"/>
  136.                     </template>
  137.                 {% endverbatim %}
  138.             </v-select>
  139.             <input name='{{props.name}}' type="hidden">
  140.         </div>
  141.         <span class="SelectIcon">
  142.             {% include "component/svg.html.twig" with {
  143.           props: {
  144.             name: 'arrow-down'
  145.           }
  146.         } %}
  147.         </span>
  148.         {# File #}
  149.     {% elseif props.type == 'file' %}
  150.         <div class="BaseInput-file u-alignVerticalCenter">
  151.             <input {{ attributes|raw }} id="input_file" type="file" accept=".doc,.docx,.jpg,.jpeg,.png,.pdf">
  152.             {% include 'component/base_icon.html.twig' with {
  153.                 props: {
  154.                     name: 'upload'
  155.                 }
  156.             } %}
  157.             <div class="BaseInput-fileValue u-alignVerticalCenter u-cDark" ref="labelValue"></div>
  158.             <div class="BaseInput-placeholder u-alignVerticalCenter" ref="labelPlaceholder">
  159.                 <div class="BaseInput-fileLabel">Choisissez votre fichier</div>
  160.                 <div class="BaseInput-fileSpec">DOC, PDF, JPG . Taille max : 2mo</div>
  161.                 <span></span>
  162.             </div>
  163.             <label for="input_file" class="BaseInput-fileFakeLabel"/>
  164.         </div>
  165.     {% endif %}
  166. </div>