继续之前验证文本框输入

时间:2011-10-06 16:46:22

标签: textbox dialog nsis nsdialogs

我有一个包含文本框的自定义对话框页面。当用户点击“下一步”按钮时,我想确保在允许安装继续之前文本框中有文本。

如何做到这一点?我尝试在nsDialogsPageLeave中添加一个检查,如果验证失败,我会调用nsDialogsPage,但这不起作用...页面底部的按钮在重新加载后不活动。

Var Dialog
Var Text
Var Text_State

Page custom nsDialogsPage nsDialogsPageLeave



Function nsDialogsPage

nsDialogs::Create 1018
Pop $Dialog

${If} $Dialog == error
    Abort
${EndIf}

${NSD_CreateText} 0 0 50% 12u $Text_State
Pop $Text

nsDialogs::Show

FunctionEnd



Function nsDialogsPageLeave

${NSD_GetText} $Text $Text_State

FunctionEnd

1 个答案:

答案 0 :(得分:3)

我处理这种情况的方法是验证leave函数中的文本,以便代码变为:

Function nsDialogsPage

    nsDialogs::Create 1018
    Pop $Dialog

    ${If} $Dialog == error
        Abort
    ${EndIf}

    ${NSD_CreateText} 0 0 50% 12u $Text_State
    Pop $Text

    nsDialogs::Show

FunctionEnd

Function nsDialogsPageLeave

    ${NSD_GetText} $Text $Text_State

    ${If} $Text_State == ""
        MessageBox MB_OK "Please enter some text"
        Abort
    ${EndIf}

FunctionEnd

这样用户可以单击“下一步”按钮,但如果没有输入任何文本,他们将收到错误消息,并且中止将使安装程序停止移动到下一页。