Blame view

common/widgets/views/site_field.php 2.17 KB
eb7e82fb   Administrator   29.02.16
1
  <?php

df799956   Administrator   16.03.16
2
  use yii\behaviors\SluggableBehavior;

eb7e82fb   Administrator   29.02.16
3
  use yii\helpers\Html;

df799956   Administrator   16.03.16
4
  

eb7e82fb   Administrator   29.02.16
5
6
7
8
9
10
11
12
13
  ?>

  <fieldset>

  

  

      <div class="field_list">

  

  

          <?php    $t = 0;

  

df799956   Administrator   16.03.16
14
          $label = 0;

eb7e82fb   Administrator   29.02.16
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
  

          for($i=1; $i <= count($model); $i++):

              $row = $i;

  

              ?>

  

          <?= Html::beginTag('div',['class'=>'form-group','id'=>isset($model[$i]['parent_key']) ? $model[$i]['parent_key'] : 0 ])?>

              <div class="input-blocks">

                  <label for="cont-site-<?= ++$label ?>">Сайт</label>

                  <input id="cont-site-<?= $label  ?>" type="url" placeholder="http://" class="form-control custom-input-2" value="<?= isset($model[$t]['value']) ? $model[$t]['value'] : '' ?>" name="Fields[site][<?=$row?>][0][site]" />

              </div>

              <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')?>

          <?php $i = ++ $t; ?>

      <?php endfor; ?>

      </div>

      <p class="btn btn-success add_field_<?= $this->context->id ?>">Добавить еще</p>

  

  </fieldset>

  <script>

      var start_i_<?=$this->context->id?> = <?=$i?>;

      var start_label_<?=$this->context->id?> = <?=$label?>; // add this var

      $( document ).ready(function(){

          $('.add_field_<?=$this->context->id?>').click(function(){

              var block     = $ (this)

                  .siblings('.field_list');

              var block_id =  $(this).parent('fieldset');

              var sub_block = '<div class="form-group" >'+

  

                  '<div class="input-blocks">'+

                  '<label for="cont-site-' + ++start_label_<?=$this->context->id?> +'">Сайт</label>'+

                  '<input id="cont-site-' + start_label_<?=$this->context->id?> +'" type="url" placeholder="http://" class="form-control custom-input-2" value="" name="Fields[site]['+ start_i_<?=$this->context->id?>++ +'][0][site]" />'+

                  '</div>'+

                  '<span title="удалить" class="glyphicon glyphicon-trash delete-field-item"></span>'+

                  '<div>';

eb7e82fb   Administrator   29.02.16
50
51
52
53
54
55
56
              block.append(sub_block);

  

          });

      });

  </script>