Guest User

cirius

a guest
Jan 6th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.72 KB | None | 0 0
  1. New :
  2. <div class="form-group">
  3. {{ form_label(form.residenceAttributes, null, {'label': 'Attributs de la résidence', 'label_attr': {'class': 'col-md-2 control-label'}}) }}
  4. <div class="col-md-6">
  5. <table class="table table-bordered no-margin">
  6. <thead>
  7. <tr>
  8. <th>Icone</th>
  9. <th>Texte</th>
  10. <th width="135">Action</th>
  11. </tr>
  12. </thead>
  13. <tbody id="attributs-add-list"
  14. data-prototype="{% filter escape %}{{ include('@App/Backend/Residence/_prototypes/attribut.html.twig', { 'attribut': form.residenceAttributes.vars.prototype }) }}{% endfilter %}">
  15. {{ form_widget(form.residenceAttributes) }}
  16. </tbody>
  17. <tbody>
  18. <tr>
  19. <td colspan="3" class="text-right">
  20. <button id="add-attribut" class="btn btn-block btn-success"><i class="fa fa-plus"></i> Ajouter un attribut</button>
  21. </td>
  22. </tr>
  23. </tbody>
  24. </table>
  25. </div>
  26. </div>
  27.  
  28. Edit :
  29. <div class="form-group">
  30. {{ form_label(edit_form.residenceAttributes, null, {'label': 'Attributs de la résidence', 'label_attr': {'class': 'col-md-2 control-label'}}) }}
  31. <div class="col-md-6">
  32. <table class="table table-bordered no-margin">
  33. <thead>
  34. <tr>
  35. <th>Icone</th>
  36. <th>Texte</th>
  37. <th width="135">Action</th>
  38. </tr>
  39. </thead>
  40. <tbody id="attributs-add-list"
  41. data-prototype="{% filter escape %}{{ include('@App/Backend/Residence/_prototypes/attribut.html.twig', { 'attribut': edit_form.residenceAttributes.vars.prototype }) }}{% endfilter %}">
  42. {% for attribut in edit_form.residenceAttributes %}
  43. <tr class="delete-parent">
  44. <td>{{ form_widget(attribut.icon) }}</td>
  45. <td>{{ form_widget(attribut.text, {'attr': {'class': 'form-control', 'placeholder' : 'Texte'}}) }}</td>
  46. <td>
  47. <button class="btn btn-danger btn-block delete-row">
  48. <i class="fa fa-times"></i> Supprimer
  49. </button>
  50. </td>
  51. </tr>
  52. {% endfor %}
  53. {{ form_widget(edit_form.residenceAttributes) }}
  54. </tbody>
  55. <tbody>
  56. <tr>
  57. <td colspan="3" class="text-right">
  58. <button id="add-attribut" class="btn btn-block btn-success"><i class="fa fa-plus"></i> Ajouter un attribut</button>
  59. </td>
  60. </tr>
  61. </tbody>
  62. </table>
  63. </div>
  64. </div>
  65.  
  66. JS :
  67. var attributsAddList = $('#attributs-add-list');
  68. $('#add-attribut').click(function () {
  69. attributsAddList.append(attributsAddList.data('prototype').replace(/__name__/g, attributsAddList.children('').length));
  70. $("[id$='_icon']").select2({
  71. theme: "bootstrap",
  72. placeholder: 'Choisir une icone',
  73. minimumResultsForSearch: Infinity,
  74. width: '100%'
  75. });
  76. return false;
  77. });
  78. $(document).on('click', '.delete-row', function () {
  79. $(this).parentsUntil('.delete-parent').parent().remove();
  80. });
  81.  
  82.  
  83.  
  84. prototype :
  85.  
  86. <tr class="delete-parent">
  87. <td>{{ form_widget(attribut.icon) }}</td>
  88. <td>{{ form_widget(attribut.text, {'attr': {'class': 'form-control', 'placeholder' : 'Texte'}}) }}</td>
  89. <td>
  90. <button class="btn btn-danger btn-block delete-row">
  91. <i class="fa fa-times"></i> Supprimer
  92. </button>
  93. </td>
  94. </tr>
Advertisement
Add Comment
Please, Sign In to add comment