【发布时间】:2018-12-04 17:25:58
【问题描述】:
我正在 R shiny 中从 sweetalert 升级到 sweetalert2,到目前为止,我已经设法让 R shiny 服务器定期响应警报消息中的“确定/取消”按钮,但现在我坚持使用下一种类型,即我曾经在其中执行一些验证的文本输入消息:
- 空
- 使用特殊字符 在将值发送到 R 之前。
Here你可以找到一个实现了sweetalert2的应用。
在新问题中,我试图用包含输入消息的消息替换该应用程序中的 javascript:
myjava <- "shinyjs.swalFromButton = function(params) {
var defaultParams = {
title: null,
html : null
};
params = shinyjs.getParams(params, defaultParams);
swal({title : params.title, html : params.html,
input: 'text',
showCancelButton : true,
showConfirmButton : true,
closeOnConfirm: false,
confirmButtonColor: '#339FFF',
allowOutsideClick: false,
inputValidator: function(value) {
if(value === '') { return !value && 'You need to write something!'}
else {
var val2= true;
Shiny.setInputValue('option2', val2, {priority: 'event'}) };
}
});
};"
到目前为止这有效,但我不知道如何添加其他检查以使用特殊字符(文件名中不允许使用) 在我的旧代码中,我有这条线用于 sweetalert (1) 工作:
var format = /[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]+/;
if(format.test(inputValue)){
swal.showInputError('Special characters are not allowed');
return false;
}
但是当我构建这个时,它在 sweetalert2 中不起作用:
myjava <- "shinyjs.swalFromButton = function(params) { swalFromButton = function(params) { var defaultParams = {
title: null,
html : null
};
params = shinyjs.getParams(params, defaultParams);
swal({title : params.title, html : params.html,
input: 'text',
showCancelButton : true,
showConfirmButton : true,
closeOnConfirm: false,
confirmButtonColor: '#339FFF',
allowOutsideClick: false,
inputValidator: function(value) {
if(value === '') { return !value && 'You need to write something!'}
else {
var format = /[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]+/;
if(format.test(value)){
return !value && 'Special characters are not allowed'}
else {
var val2= true;
Shiny.setInputValue('option2', value, {priority: 'event'})}
}
}
});
};
【问题讨论】:
标签: javascript r shiny sweetalert2