site_field.php
4.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
use yii\helpers\Html;
?>
<fieldset>
<div class="field_list">
<?php $t = 0;
$label = 0;
for($i = 1; $i <= count($model); $i++):
$row = $i;
?>
<?= Html::beginTag('div', [
'class' => 'form-group form-group-site-'. ( isset( $model[ $i ][ 'parent_key' ] ) ? $model[ $i ][ 'parent_key' ] : 0 ),
'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="text" placeholder="http://" class="form-control custom-input-2" value="<?= isset( $model[ $t ][ 'value' ] ) ? $model[ $t ][ 'value' ] : '' ?>" name="Fields[site][<?= $row ?>][0][site]"/>
</div>
<div class="help-block"></div>
<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>
<?php
$js = "
var id = 'cont-site-" . $label . "';
$('#w0').yiiActiveForm('add', {
container: '.form-group-site-" . ( isset( $model[ $i ][ 'parent_key' ] ) ? $model[ $i ][ 'parent_key' ] : 0 ) . "',
error: '.help-block',
id: id,
input: '#'+id,
name: 'Fields[site][" . $row . "][0][site]',
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});}
});
";
$this->registerJs($js, $this::POS_LOAD);
?>
<?= Html::endTag('div') ?>
<?php $i = ++$t; ?>
<?php endfor; ?>
</div>
<p class="btn btn-success add_field_<?= $this->context->id ?>"><?= Yii::t('app', 'add_more') ?></p>
</fieldset>
<?php
$js = "
var start_i_" . $this->context->id . " = " . $i . ";
var start_label_" . $this->context->id . " = " . $label . ";
$(document).on('click', '.add_field_" . $this->context->id . "', function() {
var block = $(this)
.siblings('.field_list');
var block_id = $(this).parent('fieldset');
++start_label_" . $this->context->id . ";
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>';
block.append(sub_block);
$('#w0').yiiActiveForm('add', {
container: '.form-group-site-'+start_label_" . $this->context->id . ",
error: '.help-block',
id: 'cont-site-'+start_label_" . $this->context->id . ",
input: '#cont-site-'+start_label_" . $this->context->id . ",
name: 'Fields[site][' + start_label_" . $this->context->id . "++ + '][0][site]',
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});}
});
});
";
$this->registerJs($js, $this::POS_LOAD);
?>