Blame view

common/widgets/views/phone_field.php 1.46 KB
f819c230   Yarik   test
1
2
3
4
5
6
7
8
9
10
  <?php
  use yii\helpers\Html;
  ?>
  <fieldset>
  
      <legend>Образование</legend>
  
      <p class="btn btn-success add_field">Добавить поле</p>
  
  
4f1adc01   Yarik   test
11
      <?php    $t = 0; for($i=1; $i <= count($model); $i++):
f819c230   Yarik   test
12
          $row = $i;
4f1adc01   Yarik   test
13
  
f819c230   Yarik   test
14
15
16
          ?>
  
          <?= Html::beginTag('div',['class'=>'form-group','id'=>isset($model[$i]['parent_key']) ? $model[$i]['parent_key'] : 0 ])?>
4f1adc01   Yarik   test
17
              <input type="text" placeholder="Телефон" class="form-control" value="<?= isset($model[$t]['value']) ? $model[$t]['value'] : '' ?>" name="Fields[phone][<?=$row?>][0][phone]" />
f819c230   Yarik   test
18
19
              <span data-id="<?= isset($model[$i]['parent_key']) ? $model[$i]['parent_key'] : 0 ?>" title="удалить" class="glyphicon glyphicon-trash delete-field-item"></span>
          <?= Html::endTag('div')?>
4f1adc01   Yarik   test
20
          <?php $i = ++ $t; ?>
f819c230   Yarik   test
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
      <?php endfor; ?>
  
  
  
  </fieldset>
  <script>
      $( document ).ready(function(){
          var start_i = <?=$i?>;
          $('.add_field').click(function(){
              var block = $(this).parent('fieldset');
              var block_id =  $(this).parent('fieldset');
              var sub_block = '<div class="form-group" >'+
                  '<input type="text" placeholder="Телефон" class="form-control" value="" name="Fields[phone]['+ start_i++ +'][0][phone]" />'+
                  '<span title="удалить" class="glyphicon glyphicon-trash delete-field-item"></span>'+
                  '<div>';
              block.append(sub_block);
  
          });
      });
  </script>