Chill Gal
Chill Gal

Reputation: 15

NSIS : How to keep input value from previous dialog after click Next/Back button?

If I change value in textbox and click Next button, then click Back button to back to the page again, I wanna keep new value that I changed it in textbox. How can I do?

This is my code :

AcustomPage.nsh

!macro create_AcustomPage APP_NAME CUS_FULLNAME
Page custom create_AcustomPage leave_AcustomPage
Function create_AcustomPage
        Push $0
        StrCpy $AcustomPage.FirstOpened 0
        nsDialogs::Create 1018
        Pop $AcustomPage
        GetDlgItem $AcustomPage.Button.Next $HWNDPARENT 1
        System::Call user32::GetWindowText(i$AcustomPage.Button.Next,t.s,i${NSIS_MAX_STRLEN})
        nsDialogs::CreateControl STATIC ${WS_VISIBLE}|${WS_CHILD}|${WS_CLIPSIBLINGS} 0 0u 0u 100% 20u "${AcustomPage_TITLE}"
        Pop $AcustomPage.Text
        ${NSD_CreateGroupBox} 0u 20u 100% 78% "AcustomPage Setting"
        Pop $AcustomPage.SettingBox

        ${NSD_CreateLabel} 10u 50u 20u 11u "URL:"
        Pop $AcustomPage.FULLNAME.Label
        ${NSD_CreateText} 60u 50u 60% 11u ""
        Pop $0
        ${NSD_OnChange} $0 Update_AcustomPage_Next_Button
        ${If} ${CUS_FULLNAME} != ""
            ${NSD_SetText} $0 ${CUS_FULLNAME}
        ${EndIf}
            
        Call Update_AcustomPage_Next_Button
        nsDialogs::Show
    FunctionEnd
    
    Function leave_AcustomPage
        ${NSD_GetText} $0 $CUS_FULLNAME
    FunctionEnd
    
    Function Update_AcustomPage_Next_Button
    Push $R5
        ${NSD_GetText} $0 $R5
        ${If} $R5 != ""
                    EnableWindow $AcustomPage.Button.Next 1
                    Return
        ${EndIf}
        ${If} $R5 == ""
            EnableWindow $AcustomPage.Button.Next 0
            Return
        ${EndIf}
    Pop $R5
    FunctionEnd
!macroend

Thanks,

Upvotes: 1

Views: 944

Answers (1)

Anders
Anders

Reputation: 101756

You are on the right track by always saving the text in $CUS_FULLNAME in the leave callback but you never use $CUS_FULLNAME to set the text when creating the page, you seem to try to do something with ${CUS_FULLNAME} instead!

It should probably look more like this:

${NSD_CreateText} 60u 50u 60% 11u "${CUS_FULLNAME}"
Pop $0
${If} $CUS_FULLNAME != ""
  ${NSD_SetText} $0 $CUS_FULLNAME
${EndIf}
${NSD_OnChange} $0 Update_AcustomPage_Next_Button

Here is a standalone example:

!include nsDialogs.nsh

var hCtlFullName
var FullName

Function mypageCreate
nsDialogs::Create 1018
Pop $0

${NSD_CreateText} 60u 30u 60% 11u "$FullName"
Pop $hCtlFullName
${NSD_OnChange} $hCtlFullName mypage_VerifyInput

call mypage_VerifyInput
nsDialogs::Show
FunctionEnd

Function mypageLeave
${NSD_GetText} $hCtlFullName $FullName
FunctionEnd

Function mypage_VerifyInput
Call mypageLeave ; Loads the text into $FullName
Push $0
GetDlgItem $0 $HWNDPARENT 1
${If} $FullName == ""
    EnableWindow $0 0
${Else}
    EnableWindow $0 1
${EndIf}
Pop $0
FunctionEnd

Page Custom mypageCreate mypageLeave
Page Components
Page InstFiles

Section
DetailPrint $FullName
SectionEnd

Upvotes: 2

Related Questions