我不断收到 Promise 错误:
(index):235 Uncaught (in promise) TypeError: swal.showValidationError is not a function
swal({
text: 'Not visited',
content: {
element: 'input',
attributes: {
placeholder: 'State reason',
type: 'text'
}
},
icon: 'info',
buttons: [ '@lang('global.app.cancel')', '@lang('global.app.ok')'],
closeOnConfirm: false,
animation: "slide-from-top",
preConfirm: (inputValue) => {
if (!inputValue === '') {
axios.post('setstatus',
{
order_id: $(this).attr('data-id'),
user_id: $(this).attr('data-usr'),
remark: inputValue,
order_status: 'ORDER_STATUS_NOT_VISITED'
}).then((res) => {
return res;
});
}
else {
return '';
}
},
})
.then(function(result) {
if(result === '' ) {
swal.showValidationError('@lang('global.message.state_reason')');
return false;
}
else if (result && result.data) {
swal({
text: result.data.message,
icon: (result.data.success ? 'success' : 'error')
});
if (result.data.success) {
$(this).closest('.opdracht').remove();
getOrders();
}
}
else if (result === false) {
return false;
}
});
在更改“preConfirm”和“then”部分以尝试 sweetalert 的不同配置后,我一无所知。任何建议将不胜感激
最佳答案
由于 SweetAlert2 的行为不同于它的 t4t5 当代版本,我重写了部分功能:
swal({
text: '@lang('global.message.not_visited')',
content: {
element: 'input',
attributes: {
placeholder: '@lang('global.app.reason')',
type: 'text'
}
},
icon: 'info',
buttons: [ '@lang('global.app.cancel')', '@lang('global.app.ok')'],
closeModal: false,
})
.then(function(result) {
if(result === '' ) {
console.log('back');
$('button.notvisited').click();
return false;
}
else if (result) {
console.log($('button.notvisited'));
axios.post('{{ route('mobile.order.setstatus') }}',
{
order_id: $('button.notvisited').attr('data-id'),
user_id: $('button.notvisited').attr('data-usr'),
remark: result,
order_status: 'ORDER_STATUS_NOT_VISITED'
}).then((res) => {
if( res.data ) {
swal({
text: res.data.message,
icon: ( res.data.success ? 'info' : 'error' ),
}).then( function(result) {
if (result) {
document.location.href = '{{ route('mobile.order.overview') }}';
}
});
}
});
}
});
关于javascript - SweetAlert (t4t5) 无法解决如何显示 ValidationError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49553401/