[英]Windows.alert() preventing access/data entry into text input field in electron-react app. What is the best way to handle windows.alert?
我在电子反应应用程序中有一个文本输入字段。 windows.alert() 被用来通过在给定条件下更改状态的警报。 但是在抛出警报之后,一个完全独立的表单中的输入文本字段将不允许用户在没有点击应用程序然后再点击的情况下输入数据。
我目前有一个解决方法,它使用电子的 ipcRenderer 和 ipcMain 抛出警报,但该样式与应用程序的其余部分不太匹配。 有没有办法处理 windows.alert() 不会阻止数据输入到文本输入字段? 是什么导致 windows.alert() 阻止将数据输入到文本输入中?
之前的代码示例:
function doSomething(value) {
let array = otherArray;
if (array.length == 0) {
//The below was blocking typing into <input> in a completely separate form.
window.alert("Please add expected value first")
}
}
使用来自 preload.js 和 ipcMain 的 ipcRenderer 解决代码:
function doSomething(value) {
let array = otherArray;
if (array.length == 0) {
window.api.send("send-alert", "Please add expected value first")
}
}
//in main.js
ipcMain.on("send-alert", (event, incomingMessage)=> {
let options = {
message: incomingMessage
}
dialog.showMessageBox(mainBrowserWindow, options)
}
使用 toastr 来解决这个问题。
阅读: https : //github.com/CodeSeven/toastr
触发错误或警告消息代替 window.alert() 方法。 即: toastr.warning()
或toastr.error()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.