对话框类型

Frappe 提供了一组标准对话框,在编码时非常有用。

警告对话框

警告对话框用于显示非阻塞性的消息。

它有两个参数:

  • txt: 要在 Alert Dialog 中显示的消息
  • seconds: 消息显示的持续时间。默认值为 3 seconds。

示例

show_alert(‘你好,你有新消息’, 5);


提示对话框

提示对话框用于从用户那里收集数据。

它有 4 个参数:

  • fields: 包含字段对象的列表
  • callback: 用于处理对话框中数据的函数
  • title: 对话框的标题
  • primary_label: 主按钮的标签

示例

frappe.prompt([
{‘fieldname’: ‘birth’, ‘fieldtype’: ‘Date’, ‘label’: ‘出生日期’, ‘reqd’: 1}
],
function(values){
show_alert(values, 5);
},
‘年龄验证’,
‘订阅我’
)


确认对话框

确认对话框用于在执行操作前获取用户的确认。

它有 3 个参数:

  • mesage: 要在对话框中显示的消息
  • onyes: 肯定确认时的回调函数
  • oncancel: 否定确认时的回调函数

示例

frappe.confirm(
‘确定要离开此页面吗?’,
function(){
window.close();
},
function(){
show_alert(‘感谢您继续在此操作!’)
}
)


消息打印

消息打印用于向用户显示信息。

它有 2 个参数:

  • message: 要显示的消息。可以是 HTML 字符串
  • title: 对话框的标题

示例

msgprint(“服务器状态“

  • “

“

  • “”
  • “* 28% 内存
    “
  • “* 12% 处理器
    “
  • “* 0.3% 磁盘
    “
  • “
    “, ‘服务器信息’)

自定义对话框

您可以使用 frappe.ui.Dialog 扩展并构建自己的自定义对话框

示例

var d = new frappe.ui.Dialog({
‘fields’: [
{‘fieldname’: ‘ht’, ‘fieldtype’: ‘HTML’},
{‘fieldname’: ‘today’, ‘fieldtype’: ‘Date’, ‘default’: frappe.datetime.nowdate()}
],
primary_action: function(){
d.hide();
show_alert(d.get_values());
}
});
d.fields_dict.ht.$wrapper.html(‘你好,世界’);
d.show();