footer.blade.php
12.5 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
<div class="card-footer" style="height: 50px!important;">
{{ csrf_field() }}
{{-- <div class="col-md-{{$width['label']}} ">
</div>--}}
<div class="col-md-1">
</div>
<div class="col-md-10 col-md-{{$width['field']}}">
<div class="d-flex d-sm-inline-flex align-items-center">
@if(in_array('submit', $buttons))
<button type="submit" class="btn btn-primary" {{--onclick="submitForm()"--}}>{{ trans('admin.submit') }} </button>
@endif
@if(in_array('reset', $buttons))
<button type="reset" class="btn btn-warning mr-3">{{ trans('admin.reset') }}</button>
@endif
</div>
<div class="d-flex d-sm-inline-flex align-items-center">
@if(in_array('view', $checkboxes))
<div class="custom-control custom-radio custom-control-inline">
<input type="radio" name="after-save" value="3" id="after-save3" class="custom-control-input" />
<label class="custom-control-label" for="after-save3">{{ trans('admin.view') }}</label>
</div>
@endif
@if(in_array('continue_editing', $checkboxes))
<div class="custom-control custom-radio custom-control-inline">
<input type="radio" name="after-save" value="1" id="after-save1" class="custom-control-input" />
<label class="custom-control-label" for="after-save1">{{ trans('admin.continue_editing') }}</label>
</div>
@endif
@if(in_array('continue_creating', $checkboxes))
<div class="custom-control custom-radio custom-control-inline">
<input type="radio" name="after-save" value="2" id="after-save2" class="custom-control-input" />
<label class="custom-control-label" for="after-save2">{{ trans('admin.continue_creating') }}</label>
</div>
@endif
</div>
</div>
</div>
<script type="text/javascript" src="/assets/admin/module/bootstrapValidator/js/bootstrapValidator.js"></script>
<script>
$(function () {
$('.form-inline').bootstrapValidator({
message: 'This value is not valid',
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields:{
class_name:{
validators:{
notEmpty:{
message: 'The class name is required and cannot be empty'
},
stringLength:{
min: 6,
max: 30,
message: 'The class name must be more than 6 and less than 30 characters long'
},
}
}
}
})
});
function submitForm()
{
// $.map($('.form-inline').serializeArray(), function(item, index){
// console.log(item)
// return $('[name='+item['name']+']');
// });
// $('.form-inline').find('input[type="text"]').attr("required").each(function (i, e) {
// 获取 text
// $('.form-horizontal').find('input[type="text"]').each(function (i, e) {
// console.log(e);
// });
let ok = true;
let value = '';
let form_group = null;
let target ='';
let target_dom = null;
let index = 0;
$('.form-horizontal').find('[required="1"]').each(function (i, e) {
let tagName = e.tagName.toLowerCase();
value = $(e).val();
form_group = $(e).closest('.form-group');
let name = $(e).attr('name')
if (i === 0) {
target = name;
}
switch ($(e).attr('type')) {
case 'radio':
case 'checkbox':
let val = $('input:'+$(e).attr('type')+'[name="'+name+'"]:checked').val();
if (!val) {
form_group.addClass('has-error');
let label = form_group.find('label.asterisk').text();
let validation = "{{trans('validation.required')}}";
validation = validation.replace(':attribute', label)
form_group.find('.text-muted').show().find('span').text(validation);
ok = false;
// 找到第一个需要验证的对象
if (index === 0) {
target_dom = $(e);
}
index ++;
} else {
form_group.find('.text-muted').hide();
// 判断是否
if (val === 'other' || val === 1) {
if (form_group.next('.cascade-group').length > 0 ) {
// 获取 input
let dom = $('#'+name+'_supplement');
console.log(name+'_supplement');
if (dom.length > 0) {
console.log(dom.val())
if (!dom.val()) {
form_group.next('.cascade-group').find('.form-group').addClass('has-error');
form_group.next('.cascade-group').find('.text-muted').show().find('span').text("{{__('please_fill_other')}}");
ok = false;
// 找到第一个需要验证的对象
if (index === 0) {
target_dom = $(e);
}
index ++;
}
}
} else {
form_group.removeClass('has-error');
}
} else {
form_group.removeClass('has-error');
}
}
break;
// case 'checkbox':
// let val_c = $('input:checkbox[name="'+name+'"]:checked').val();
// console.log(val_c)
// break;
default:
if (!value) {
form_group.addClass('has-error');
let label = form_group.find('label').text();
let validation = "{{trans('validation.required')}}";
validation = validation.replace(':attribute', label)
form_group.find('.text-muted').show().find('span').text(validation);
// 找到第一个需要验证的对象
if (index === 0) {
target_dom = $(e);
}
index ++;
ok = false;
} else {
form_group.removeClass('has-error');
form_group.find('.text-muted').hide();
}
}
{{--if (tagName === 'input') {--}}
{{-- switch ($(e).attr('type')) {--}}
{{-- case 'text': // 输入框--}}
{{-- if (!value) {--}}
{{-- form_group.addClass('has-error');--}}
{{-- let name = $(e).attr('name');--}}
{{-- --}}{{--let field = "\{{__('\"+name+\"')}}\";--}}
{{-- // console.log($(e).attr('name'));--}}
{{-- // console.log(field);--}}
{{-- form_group.find('.text-muted').show().find('b').text("{{trans('validation.required')}}");--}}
{{-- ok = false;--}}
{{-- } else {--}}
{{-- form_group.removeClass('has-error');--}}
{{-- form_group.find('.text-muted').hide();--}}
{{-- }--}}
{{-- break;--}}
{{-- case 'radio': // 输入框--}}
{{-- if (!value) {--}}
{{-- form_group.addClass('has-error');--}}
{{-- let name = $(e).attr('name');--}}
{{-- --}}{{--let field = "\{{__('\"+name+\"')}}\";--}}
{{-- // console.log($(e).attr('name'));--}}
{{-- // console.log(field);--}}
{{-- form_group.find('.text-muted').show().find('b').text("{{trans('validation.required')}}");--}}
{{-- ok = false;--}}
{{-- } else {--}}
{{-- form_group.removeClass('has-error');--}}
{{-- form_group.find('.text-muted').hide();--}}
{{-- }--}}
{{-- break;--}}
{{-- }--}}
{{--} else if (tagName === 'select') {--}}
{{-- if (!value) {--}}
{{-- form_group.addClass('has-error');--}}
{{-- let name = $(e).attr('name');--}}
{{-- form_group.find('.text-muted').show().find('b').text("{{trans('validation.required')}}");--}}
{{-- ok = false;--}}
{{-- } else {--}}
{{-- form_group.removeClass('has-error');--}}
{{-- form_group.find('.text-muted').hide();--}}
{{-- }--}}
{{--}--}}
// console.log(e.tagName);
});
// $('.form-inline').bootstrapValidator('validate');
let $r;
if (ok) {
// TODO 特殊处理
let c_url = "{{request()->url()}}";
let url = c_url.replace('/create', '').replace('/edit', '');
let id = 0;
if (c_url.indexOf('/edit')) {
let arr = url.split('/');
id = arr[arr.length - 1];
url = url.replace('/' + id, '');
}
let dom_mobile = $("#mobile");
let mobile = dom_mobile.val();
$r = verifyUnique(dom_mobile, url, id, 'mobile', mobile);
if ($r !== true) {
return false;
} else {
ok = true;
}
let dom_id_number = $("#ID_number");
let ID_number = dom_id_number.val();
$r = verifyUnique(dom_id_number, url, id, 'ID_number', ID_number);
if ($r !== true) {
return false;
} else {
ok = true;
}
}
//
if (ok) {
document.forms[0].submit();
} else {
let top = target_dom.offset().top;
$("body, html").stop().animate({
scrollTop: top - 10
});
}
}
/**
* 验证唯一性
*
* @param url
* @param dom
* @param id
* @param key
* @param value
*/
function verifyUnique(dom, url, id, key, value)
{
if (!value) {
return true;
}
url = url + '/verify?id=' + id + '&key=' + key +'&value='+value;
let ok = true;
let target_dom = null;
$.ajax({
url: url,
type: "get",
async: false,
success: function (res) {
let form_group = dom.closest('.form-group');
if (res.code === 0) {
form_group.removeClass('has-error');
form_group.find('.text-muted').hide();
} else {
form_group.addClass('has-error');
form_group.find('.text-muted').show().find('span').text(res.message);
ok = false;
target_dom = form_group;
let top = target_dom.offset().top;
$("body, html").stop().animate({
scrollTop: top - 10
});
// return false;
}
},
error: function (res) {
},
complete: function (xhr, status) {
}
});
return ok;
// return target_dom;//{"ok":ok, "target_dom":target_dom};
}
</script>