- NSIS Discussion
- if checked, then disable a "Field"
Archive: if checked, then disable a "Field"
OsmanY22
24th August 2006 14:42 UTC
if checked, then disable a "Field"
Hi.
I have a custom Page. In this Custom Page, there are some Fields (Label, Text, Password) and Checkbox. Now I want to do, that, when a checkbox is checked, then an of the Fields (Text) should be disabled!
Lood at the Picture "enabled&disabled.jpg"
Thx @all
ReadINIStr$0 "$PLUGINSDIR\setup.ini" "Field 3" "State"
StrCpy $OCIP $0
ReadINIStr$0 "$PLUGINSDIR\setup.ini" "Field 5" "State"
StrCpy $OCUSER $0
ReadINIStr$0 "$PLUGINSDIR\setup.ini" "Field 7" "State"
StrCpy $OCPWD $0
ReadINIStr$0 "$PLUGINSDIR\setup.ini" "Field 10" "State"
StrCpy $DINAME $0
ReadINIStr$0 "$PLUGINSDIR\setup.ini" "Field 12" "State"
StrCpy $DIUSER $0
ReadINIStr$0 "$PLUGINSDIR\setup.ini" "Field 14" "State"
StrCpy $DIPWD $0
ReadINIStr$0 "$PLUGINSDIR\setup.ini" "Field 16" "State"
StrCmp $0 0 done
ExecWait "$INSTDIR\wrapper\bin\Install_MediaServer.bat"
Delete "$INSTDIR\wrapper\conf\password.conf"
>done:
Comperio
24th August 2006 15:21 UTC
First, make sure you have the notify flag set on your checkbox. Then, in the page's callback function, so this: (PS: your original code was missing a backslash between $PLUGINSDIR and the name of your page file.)
Function callback
push $0
push $1
ReadIniStr "$PLUGINSDIR\setup.ini" "Settings" "State"
; compare $0 to the field of your checkbox.
; (This example assumes field 8 is your checkbox)
StrCpy $0 8 changestate 0
; *** normal callback code goes here ***
changestate:
; the next lines assume that your field to
; gray out is field 9
ReadIniStr $0 "$PLUGINSDIR\Setup.ini" "Field 9" "HWND"
ReadIniStr $1 "$PLUGINSDIR\Setup.ini" "Field 8" "state"
StrCmp $1 1 disable enable
disable:
EnableWindow $0 0
; and write the value just in case the user returns to this screen:
WriteIniStr "$PLUGINGSDIR\Setup.ini" "Field 9" "Flags" "DISABLED"
pop $1
pop $0
abort
enable:
EnableWindow $0 1
; and write the value just in case the user returns to this screen:
WriteIniStr "$PLUGINGSDIR\Setup.ini" "Field 9" "Flags" ""
pop $1
pop $0
abort
FunctionEnd
***EDIT: I changed the code above to check for the state of the checkbox and enable/disable as needed. (minor details...)
OsmanY22
24th August 2006 15:41 UTC
sorry, but i don't understand, where I should give the function "callback"?
This my Code now ... Field 16 is my checkbox and Field 12 and 14 must be disabled, when this checkbox ist NOT checked.
Do you know, what i mean?
ReadINIStr $0 "$PLUGINSDIR\setup.ini" "Field 3" "State"
StrCpy "$OCIP" $0
ReadINIStr $0 "$PLUGINSDIR\setup.ini" "Field 5" "State"
StrCpy $OCUSER $0
ReadINIStr $0 "$PLUGINSDIR\setup.ini" "Field 7" "State"
StrCpy $OCPWD $0
ReadINIStr $0 "$PLUGINSDIR\setup.ini" "Field 10" "State"
StrCpy $DINAME $0
ReadINIStr $0 "$PLUGINSDIR\setup.ini" "Field 12" "State"
StrCpy $DIUSER $0
ReadINIStr $0 "$PLUGINSDIR\setup.ini" "Field 14" "State"
StrCpy $DIPWD $0
ReadINIStr $0 "$PLUGINSDIR\setup.ini" "Field 16" "State"
StrCmp $0 0 done
ExecWait "$INSTDIR\wrapper\bin\Install_MediaServer.bat"
Delete "$INSTDIR\wrapper\conf\password.conf"
done:
I don't forget "/" ... but the editor of PHP doesn't show it.
Comperio
25th August 2006 04:22 UTC
Any custom page you insert has a show function and a leave function (also called a callback function).
Use them in your page command like this:
Page custom showfunction leavefunction
(in this example, the "leavefunction" is what I'm calling the "callback" function.)
Refer to the documentation and the examples for more info. (${NSISDIR}\examples\InstallOptions\testnotify.nsi offers a good example of how to use page callbacks.)
OsmanY22
25th August 2006 11:29 UTC
Thx a lot man!!!
it workssss!!!
FALSE: "$PLUGINGSDIR"
RIGHT: "$PLUGINSDIR"
OsmanY22
25th August 2006 11:37 UTC
What does this text mean??
; compare $0 to the field of your checkbox.
; (This example assumes field 8 is your checkbox)
StrCpy $0 8 changestate 0
It works with to disable an Field, but i cant continue with the install.
What is the problem??
Function callback
push $0
push $1
ReadINIStr $0 "$PLUGINSDIR\setup.ini" "Field 3" "State"
StrCpy "$OCIP" $0
ReadINIStr $0 "$PLUGINSDIR\setup.ini" "Field 5" "State"
StrCpy $OCUSER $0
ReadINIStr $0 "$PLUGINSDIR\setup.ini" "Field 7" "State"
StrCpy $OCPWD $0
ReadINIStr $0 "$PLUGINSDIR\setup.ini" "Field 10" "State"
StrCpy $DINAME $0
ReadINIStr $0 "$PLUGINSDIR\setup.ini" "Field 12" "State"
StrCpy $DIUSER $0
ReadINIStr $0 "$PLUGINSDIR\setup.ini" "Field 14" "State"
StrCpy $DIPWD $0
ReadINIStr $0 "$PLUGINSDIR\setup.ini" "Field 16" "State"
StrCmp $0 8 changestate 0
changestate:
; gray out is field 14
ReadIniStr $0 "$PLUGINSDIR\Setup.ini" "Field 14" "HWND"
ReadIniStr $1 "$PLUGINSDIR\Setup.ini" "Field 16" "state"
StrCmp $1 0 disable enable
disable:
EnableWindow $0 0
; and write the value just in case the user returns to this screen:
WriteIniStr "$PLUGINSDIR\Setup.ini" "Field 14" "Flags" "DISABLED"
pop $1
pop $0
abort
enable:
EnableWindow $0 1
; and write the value just in case the user returns to this screen:
WriteIniStr "$PLUGINSDIR\Setup.ini" "Field 14" "Flags" ""
pop $1
pop $0
abort
FunctionEnd
Now last question...how can I "disable" more Fields??
I want to disable Filed 12 and 14.
Comperio
26th August 2006 15:01 UTC
oops! My bad..
It was a typo on my part--sorry 'bout that!
The line
StrCpy $0 8 changestate 0
should have been:
StrCmp $0 8 changestate 0
And thanks for catching my other typo.
Edit:
OsmanY22, I sent you a PM explaining the nuts and bolts of this script a little better so that you'd have a better understanding of how to implement it in your situation.
TheShadowHawk
21st November 2006 09:51 UTC
Please can someone help me! I have a custom page with 2 fields. a checkbox (field 2) and a text box (field 4)
I want to make it so if the checkbox is ticked, the textbox is enabled, and if unticked the textbox is disabled. I have followed code snippets from this forum and yet cannot make it work. I know I am close! Any helpers?
Thanks!
; get value of checkbox
!insertmacro MUI_INSTALLOPTIONS_READ $R4 "OptionDetails.ini" "Field 2" "State"
; get the field triggered
!insertmacro MUI_INSTALLOPTIONS_READ $R0 "OptionDetails.ini" "Settings" "State"
${if} $R0 == "2" ; if field 2 clicked
ReadIniStr $R3 "OptionDetails.ini" "Field 4" "HWND"
${if} $R4 == "1"
EnableWindow $R3 1
WriteIniStr "OptionDetails.ini" "Field 4" "Flags" ""
${else}
EnableWindow $R3 0
WriteIniStr "OptionDetails.ini" "Field 4" "Flags" "DISABLED"
${EndIf}
abort ; return to page
${EndIf}
kichik
21st November 2006 18:37 UTC
ReadIniStr requires a full path. Use $PLUGINSDIR\optionDetails.ini or the MUI macros. Same goes to WriteIniStr.
TheShadowHawk
21st November 2006 22:57 UTC
fixed!
Thanks very much kichik! That fixed it for me! :D