Search code examples
textboxdialognsisnsdialogs

Validate text box input before continuing


I have a custom dialog page that contains a text box. When the user hits the "Next" button, I want to make sure that there is text in the text box before allowing the installation to continue.

How can this be done? I tried adding a check in nsDialogsPageLeave, where I call nsDialogsPage if the validation fails, but this does not work...the buttons at the bottom of the page are not active after it reloads.

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

Solution

  • The way I've dealt with this situation is to validate the text in the leave function so that your code becomes:

    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
    

    This way the user can click the Next button but they will get an error message if no text has been entered and the Abort will stop the installer moving to the next page.