Commit 4476eb3511969dc118646c9c5759449e9fae3e84

Authored by Yarik
1 parent 236a608c

test

.gitignore
  1 +/frontend/models/ValidateHelper.php
1 2 /tests
2 3 /frontend/web/js/Validation.ts
3 4 /frontend/web/js/typescript.ts
... ...
common/widgets/views/phone_field.php
1 1 <?php
2 2 use yii\helpers\Html;
3   - use yii\validators\RegularExpressionValidator;
4   - use yii\widgets\MaskedInput;
5 3  
6 4 ?>
7 5 <fieldset>
8 6  
9 7 <div class="field_list">
10 8  
11   -
12 9 <?php $t = 0;
13 10  
14 11 $label = 0; // add this var
... ... @@ -17,14 +14,29 @@
17 14 $row = $i;
18 15 ?>
19 16 <?= Html::beginTag('div', [
20   - 'class' => 'form-group',
  17 + 'class' => 'form-group form-group-phone-' . ( isset( $model[ $i ][ 'parent_key' ] ) ? $model[ $i ][ 'parent_key' ] : 0 ),
21 18 'id' => isset( $model[ $i ][ 'parent_key' ] ) ? $model[ $i ][ 'parent_key' ] : 0,
22 19 ]) ?>
23 20 <div class="input-blocks">
24 21 <label for="cont-phone-<?= ++$label ?>">Телефон</label>
25   - <input id="cont-phone-<?= $label ?>" type="tel" pattern="^\+?(?:\d{0,3})?[\(\s]?\d{0,5}[\)\s]?\d{3}[-\s]?\d{2}[-\s]?\d{2}$" placeholder="+xx(xxx)xxx-xx-xx" class="form-control custom-input-2" value="<?= isset( $model[ $t ][ 'value' ] ) ? $model[ $t ][ 'value' ] : '' ?>" name="Fields[phone][<?= $row ?>][0][phone]"/>
  22 + <input id="cont-phone-<?= $label ?>" type="tel" placeholder="+xx(xxx)xxx-xx-xx" class="form-control custom-input-2" value="<?= isset( $model[ $t ][ 'value' ] ) ? $model[ $t ][ 'value' ] : '' ?>" name="Fields[phone][<?= $row ?>][0][phone]"/>
26 23 </div>
  24 + <div class="help-block"></div>
27 25 <span data-id="<?= isset( $model[ $i ][ 'parent_key' ] ) ? $model[ $i ][ 'parent_key' ] : 0 ?>" title="<?= Yii::t('app', 'add') ?>" class="glyphicon glyphicon-trash delete-field-item"></span>
  26 + <?php
  27 + $js = "
  28 + var id = 'cont-phone-" . $label . "';
  29 + $('#w0').yiiActiveForm('add', {
  30 + container: '.form-group-phone-" . ( isset( $model[ $i ][ 'parent_key' ] ) ? $model[ $i ][ 'parent_key' ] : 0 ) . "',
  31 + error: '.help-block',
  32 + id: id,
  33 + input: '#'+id,
  34 + name: 'Fields[phone][" . $row . "][0][phone]',
  35 + validate: function(attribute, value, messages, deferred) {yii.validation.regularExpression(value, messages, {'pattern':/^\+?(?:\d{0,3})?[\(\s]?\d{0,5}[\)\s]?\d{3}[-\s]?\d{2}[-\s]?\d{2}$/,'not':false,'message':'Телефон введен неверно . ','skipOnEmpty':1});}
  36 + });
  37 + ";
  38 + $this->registerJs($js, $this::POS_LOAD);
  39 + ?>
28 40 <?= Html::endTag('div') ?>
29 41 <?php $i = ++$t; ?>
30 42 <?php endfor; ?>
... ... @@ -33,25 +45,28 @@
33 45 <p class="btn btn-success add_field_<?= $this->context->id ?>">Добавить еще</p>
34 46  
35 47 </fieldset>
36   -<script>
37   - var start_i_<?=$this->context->id?> = <?=$i?>;
38   - var start_label_<?=$this->context->id?> = <?=$label?>; // add this var
39   - $(document).ready(
40   - function()
41   - {
42   - $('.add_field_<?=$this->context->id?>').click(
43   - function()
44   - {
45   - var block = $(this)
  48 +<?php
  49 + $js = "
  50 + var start_i_" . $this->context->id . " = " . $i . ";
  51 + var start_label_" . $this->context->id . " = " . $label . ";
  52 + $(document).on('click', '.add_field_" . $this->context->id . "', function() {
  53 + var block = $(this)
46 54 .siblings('.field_list');
47 55 var block_id = $(this).parent('fieldset');
48   - var sub_block = '<div class="form-group" >' + '<div class="input-blocks">' + '<label for="cont-phone-' + ++start_label_<?=$this->context->id?> + '">Телефон</label>' + '<input id="cont-phone-' + start_label_<?=$this->context->id?> + '" type="tel" pattern="^\\+?(?:\\d{0,3})?[\\(\\s]?\\d{0,5}[\\)\\s]?\\d{3}[-\\s]?\\d{2}[-\\s]?\\d{2}$" placeholder="+xx(xxx)xxx-xx-xx" class="form-control custom-input-2" value="" name="Fields[phone][' + start_i_<?=$this->context->id?>++ + '][0][phone]" />' + '</div>' + '<span class="glyphicon glyphicon-trash delete-field-item custom-remove-ico"></span>' + '<div>';
  56 + ++start_label_" . $this->context->id . ";
  57 + var sub_block = '<div class=\"form-group form-group-phone-'+start_label_" . $this->context->id . "+'\" >' + '<div class=\"input-blocks\">' + '<label for=\"cont-phone-' + start_label_" . $this->context->id . " + '\">Телефон</label>' + '<input id=\"cont-phone-' + start_label_" . $this->context->id . " + '\" type=\"tel\" placeholder=\"+xx(xxx)xxx-xx-xx\" class=\"form-control custom-input-2\" value=\"\" name=\"Fields[phone][' + start_i_" . $this->context->id . "++ + '][0][phone]\" />' + '</div><div class=\"help-block\"></div><span class=\"glyphicon glyphicon-trash delete-field-item custom-remove-ico\"></span>' + '<div>';
49 58 block.append(sub_block);
50   -
51   - }
52   - );
53   - }
54   - );
55   -</script>
  59 + $('#w0').yiiActiveForm('add', {
  60 + container: '.form-group-phone-'+start_label_" . $this->context->id . ",
  61 + error: '.help-block',
  62 + id: 'cont-phone-'+start_label_" . $this->context->id . ",
  63 + input: '#cont-phone-'+start_label_" . $this->context->id . ",
  64 + name: 'Fields[phone][' + start_label_" . $this->context->id . "++ + '][0][phone]',
  65 + validate: function(attribute, value, messages, deferred) {yii.validation.regularExpression(value, messages, {'pattern':/^\+?(?:\d{0,3})?[\(\s]?\d{0,5}[\)\s]?\d{3}[-\s]?\d{2}[-\s]?\d{2}$/,'not':false,'message':'Телефон введен неверно . ','skipOnEmpty':1});}
  66 + });
  67 + });
  68 + ";
  69 + $this->registerJs($js, $this::POS_LOAD);
  70 +?>
56 71  
57 72  
... ...
common/widgets/views/site_field.php
1 1 <?php
2   -use yii\behaviors\SluggableBehavior;
3   -use yii\helpers\Html;
  2 + use yii\helpers\Html;
4 3  
5 4 ?>
6 5 <fieldset>
7 6  
8   -
9 7 <div class="field_list">
10 8  
  9 + <?php $t = 0;
11 10  
12   - <?php $t = 0;
13   -
14   - $label = 0;
15   -
16   - for($i=1; $i <= count($model); $i++):
17   - $row = $i;
  11 + $label = 0;
18 12  
19   - ?>
20   -
21   - <?= Html::beginTag('div',['class'=>'form-group','id'=>isset($model[$i]['parent_key']) ? $model[$i]['parent_key'] : 0 ])?>
22   - <div class="input-blocks">
23   - <label for="cont-site-<?= ++$label ?>">Сайт</label>
24   - <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]" />
25   - </div>
26   - <span data-id="<?= isset($model[$i]['parent_key']) ? $model[$i]['parent_key'] : 0 ?>" title="<?= Yii::t('app','add') ?>" class="glyphicon glyphicon-trash delete-field-item"></span>
27   - <?= Html::endTag('div')?>
28   - <?php $i = ++ $t; ?>
29   - <?php endfor; ?>
  13 + for($i = 1; $i <= count($model); $i++):
  14 + $row = $i;
  15 + ?>
  16 + <?= Html::beginTag('div', [
  17 + 'class' => 'form-group form-group-site-'. ( isset( $model[ $i ][ 'parent_key' ] ) ? $model[ $i ][ 'parent_key' ] : 0 ),
  18 + 'id' => isset( $model[ $i ][ 'parent_key' ] ) ? $model[ $i ][ 'parent_key' ] : 0,
  19 + ]) ?>
  20 + <div class="input-blocks">
  21 + <label for="cont-site-<?= ++$label ?>">Сайт</label>
  22 + <input id="cont-site-<?= $label ?>" type="text" placeholder="http://" class="form-control custom-input-2" value="<?= isset( $model[ $t ][ 'value' ] ) ? $model[ $t ][ 'value' ] : '' ?>" name="Fields[site][<?= $row ?>][0][site]"/>
  23 + </div>
  24 + <div class="help-block"></div>
  25 + <span data-id="<?= isset( $model[ $i ][ 'parent_key' ] ) ? $model[ $i ][ 'parent_key' ] : 0 ?>" title="<?= Yii::t('app', 'add') ?>" class="glyphicon glyphicon-trash delete-field-item"></span>
  26 + <?php
  27 + $js = "
  28 + var id = 'cont-site-" . $label . "';
  29 + $('#w0').yiiActiveForm('add', {
  30 + container: '.form-group-site-" . ( isset( $model[ $i ][ 'parent_key' ] ) ? $model[ $i ][ 'parent_key' ] : 0 ) . "',
  31 + error: '.help-block',
  32 + id: id,
  33 + input: '#'+id,
  34 + name: 'Fields[site][" . $row . "][0][site]',
  35 + validate: function(attribute, value, messages, deferred) {yii.validation.url(value, messages, {\"pattern\":/^(http|https):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(?::\d{1,5})?(?:$|[?\/#])/i,\"message\":\"Введенный адрес не является правильным URL.\",\"enableIDN\":false,\"skipOnEmpty\":1});}
  36 + });
  37 + ";
  38 + $this->registerJs($js, $this::POS_LOAD);
  39 + ?>
  40 + <?= Html::endTag('div') ?>
  41 + <?php $i = ++$t; ?>
  42 + <?php endfor; ?>
30 43 </div>
31   - <p class="btn btn-success add_field_<?= $this->context->id ?>"><?= Yii::t('app','add_more') ?></p>
  44 + <p class="btn btn-success add_field_<?= $this->context->id ?>"><?= Yii::t('app', 'add_more') ?></p>
32 45  
33 46 </fieldset>
34   -<script>
35   - var start_i_<?=$this->context->id?> = <?=$i?>;
36   - var start_label_<?=$this->context->id?> = <?=$label?>; // add this var
37   - $( document ).ready(function(){
38   - $('.add_field_<?=$this->context->id?>').click(function(){
39   - var block = $ (this)
40   - .siblings('.field_list');
41   - var block_id = $(this).parent('fieldset');
42   - var sub_block = '<div class="form-group" >'+
43   -
44   - '<div class="input-blocks">'+
45   - '<label for="cont-site-' + ++start_label_<?=$this->context->id?> +'">Сайт</label>'+
46   - '<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]" />'+
47   - '</div>'+
48   - '<span title="<?= Yii::t('app','add') ?>" class="glyphicon glyphicon-trash delete-field-item"></span>'+
49   - '<div>';
50   - block.append(sub_block);
51   -
52   - });
53   - });
54   -</script>
  47 +<?php
  48 + $js = "
  49 + var start_i_" . $this->context->id . " = " . $i . ";
  50 + var start_label_" . $this->context->id . " = " . $label . ";
  51 + $(document).on('click', '.add_field_" . $this->context->id . "', function() {
  52 + var block = $(this)
  53 + .siblings('.field_list');
  54 + var block_id = $(this).parent('fieldset');
  55 + ++start_label_" . $this->context->id . ";
  56 + var sub_block = '<div class=\"form-group form-group-site-'+start_label_" . $this->context->id . "+'\" >' + '<div class=\"input-blocks\">' + '<label for=\"cont-site-' + start_label_" . $this->context->id . " + '\">Сайт</label>' + '<input id=\"cont-site-' + start_label_" . $this->context->id . " + '\" type=\"text\" placeholder=\"http://\" class=\"form-control custom-input-2\" value=\"\" name=\"Fields[site][' + start_i_" . $this->context->id . "++ + '][0][site]\" />' + '</div><div class=\"help-block\"></div><span class=\"glyphicon glyphicon-trash delete-field-item custom-remove-ico\"></span>' + '<div>';
  57 + block.append(sub_block);
  58 + $('#w0').yiiActiveForm('add', {
  59 + container: '.form-group-site-'+start_label_" . $this->context->id . ",
  60 + error: '.help-block',
  61 + id: 'cont-site-'+start_label_" . $this->context->id . ",
  62 + input: '#cont-site-'+start_label_" . $this->context->id . ",
  63 + name: 'Fields[site][' + start_label_" . $this->context->id . "++ + '][0][site]',
  64 + validate: function(attribute, value, messages, deferred) {yii.validation.url(value, messages, {\"pattern\":/^(http|https):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(?::\d{1,5})?(?:$|[?\/#])/i,\"message\":\"Введенный адрес не является правильным URL.\",\"enableIDN\":false,\"skipOnEmpty\":1});}
  65 + });
  66 + });
  67 + ";
  68 + $this->registerJs($js, $this::POS_LOAD);
  69 +?>
55 70  
56 71  
... ...
frontend/views/site/index.php
1 1 <?php
  2 + use frontend\models\ValidateHelper;
2 3 use \yii\helpers\Html;
3 4 use \common\models\Specialization;
4 5  
... ...
frontend/web/css/style.css
... ... @@ -7838,6 +7838,10 @@ input.disabled.admin-check:checked + label, input.disabled.admin-check:checked +
7838 7838 background: #fff
7839 7839 }
7840 7840  
  7841 +.field_list .help-block {
  7842 + float: left;
  7843 +}
  7844 +
7841 7845 .help-block:before {
7842 7846 content: '';
7843 7847 width: 20px;
... ...