Blame view

common/widgets/views/phone_field.php 2.1 KB
f819c230   Yarik   test
1
  <?php
f6a2a0d5   Yarik   test
2
      use yii\helpers\Html;
f819c230   Yarik   test
3
4
5
  ?>
  <fieldset>
  
658d13d4   Administrator   09.02.16
6
      <div class="field_list">
f819c230   Yarik   test
7
8
  
  
29f6660a   Виталий   tokar commit
9
10
11
12
13
      <?php    $t = 0;
  
      $label = 0; // add this var
  
      for($i=1; $i <= count($model); $i++):
f819c230   Yarik   test
14
          $row = $i;
4f1adc01   Yarik   test
15
  
f819c230   Yarik   test
16
17
18
          ?>
  
          <?= Html::beginTag('div',['class'=>'form-group','id'=>isset($model[$i]['parent_key']) ? $model[$i]['parent_key'] : 0 ])?>
29f6660a   Виталий   tokar commit
19
          <div class="input-blocks">
7fe508fb   Виталий   tokar commit
20
21
              <label for="cont-phone-<?= ++$label ?>">Телефон</label>
              <input id="cont-phone-<?= $label  ?>" type="text" placeholder="" class="form-control custom-input-2" value="<?= isset($model[$t]['value']) ? $model[$t]['value'] : '' ?>" name="Fields[phone][<?=$row?>][0][phone]" />
29f6660a   Виталий   tokar commit
22
23
          </div>
              <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
24
          <?= Html::endTag('div')?>
4f1adc01   Yarik   test
25
          <?php $i = ++ $t; ?>
f819c230   Yarik   test
26
27
      <?php endfor; ?>
  
658d13d4   Administrator   09.02.16
28
      </div>
29f6660a   Виталий   tokar commit
29
      <p class="btn btn-success add_field_<?= $this->context->id ?>">Добавить еще</p>
f819c230   Yarik   test
30
31
32
  
  </fieldset>
  <script>
f6a2a0d5   Yarik   test
33
      var start_i_<?=$this->context->id?> = <?=$i?>;
29f6660a   Виталий   tokar commit
34
      var start_label_<?=$this->context->id?> = <?=$label?>; // add this var
f819c230   Yarik   test
35
      $( document ).ready(function(){
f6a2a0d5   Yarik   test
36
          $('.add_field_<?=$this->context->id?>').click(function(){
658d13d4   Administrator   09.02.16
37
38
              var block     = $ (this)
                  .siblings('.field_list');
f819c230   Yarik   test
39
40
              var block_id =  $(this).parent('fieldset');
              var sub_block = '<div class="form-group" >'+
29f6660a   Виталий   tokar commit
41
                  '<div class="input-blocks">'+
7fe508fb   Виталий   tokar commit
42
43
                  '<label for="cont-phone-' + ++start_label_<?=$this->context->id?> +'">Телефон</label>'+
                  '<input id="cont-phone-' + start_label_<?=$this->context->id?> +'" type="text" placeholder="" class="form-control custom-input-2" value="" name="Fields[phone]['+ start_i_<?=$this->context->id?>++ +'][0][phone]" />'+
29f6660a   Виталий   tokar commit
44
45
                  '</div>'+
                  '<span class="glyphicon glyphicon-trash delete-field-item custom-remove-ico"></span>'+
f819c230   Yarik   test
46
                  '<div>';
29f6660a   Виталий   tokar commit
47
  //            console.log(block);
f819c230   Yarik   test
48
49
50
51
52
              block.append(sub_block);
  
          });
      });
  </script>