Blame view

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