Home   Archive   Permalink



Setting a drop-down at run time

I know how to set the values of a drop-down list when making a layout, and I know how to access the value that was selected, but it seems I do not know how to set the values of a drop-down list after the layout has been created and viewed. In the sample below, I have two drop-downs. The top one is for a main category of something-or-other, and the one beneath is for sub-categories of the main category. I want the sub-category drop-down to change depending on which main category was selected. That is what I seem to be unable to do, and I wonder if anyone can assist.
    
Thank you.
    
R E B O L []
    
CATEGORIES: [
     "ActiveDirectory" ["ResetPassword" "UnlockAccount"]
     "Laptop" ["LoginFailure" "XXX" "yyy"]
     "Phones" ["NewCord" "xxx" "yyy"]
]
SUBCATS: []
    
LOAD-SUBCAT: does [
     SUBCATS: copy []
     SUBCATS: select CATEGORIES MAIN-CATEGORY/text
     MAIN-SUBCAT/data: SUBCATS ;; This seems to be the problem spot
     show MAIN-SUBCAT
     set-face DEBUG-TEXT mold SUBCATS ;; for debugging
]
    
MAIN-WINDOW: layout [
     MAIN-CATEGORY: drop-down 120 data (extract CATEGORIES 2) [LOAD-SUBCAT]
     MAIN-SUBCAT: drop-down 120
     button "Quit" [quit]
     DEBUG-TEXT: info 200 ;; for debugging
     box 200x100 ;; So drop-down will show
]
    
view center-face MAIN-WINDOW


posted by:   Steven White       4-Sep-2018/18:09:04-7:00



Try this:
    
CATEGORIES: [
     "ActiveDirectory" ["ResetPassword" "UnlockAccount"]
     "Laptop" ["LoginFailure" "XXX" "yyy"]
     "Phones" ["NewCord" "xxx" "yyy"]
]
SUBCATS: []
        
LOAD-SUBCAT: does [
     SUBCATS: copy select CATEGORIES get-face MAIN-CATEGORY
     ms/reset
     ms/list-data: SUBCATS
     set-face ms subcats/1
]
        
MAIN-WINDOW: layout [
     MAIN-CATEGORY: drop-down 120 data (extract CATEGORIES 2) [LOAD-SUBCAT]
     ms: drop-down 120
     button "Quit" [quit]
     box 200x100 ;; So drop-down will show
]
        
view center-face MAIN-WINDOW

posted by:   Nick       4-Sep-2018/22:54:02-7:00



Thank you, that did work perfectly. I wonder if i might ask a couple questions about it since I have to explain it and can't.    
    
Regarding "ms/list-data: SUBCATS" if I had to guess at an explanation I would say that "list-data" is the item in a drop-down face that refers to drop-down values, and code like "MAIN-CATEGORY: drop-down 120 data (extract CATEGORIES 2)" is what loads "list-data" at the time a layout is generated. If one later wants to set a drop-down manually, then "list-data" is the item that must be set. How you discovered that is amazing to me.
    
But, the line "ms/reset" is unfamiliar. If I had to guess, I would guess that it is a function in a drop-down face in the way that "get-face" and "set-face" are functions in certain other faces. Its use is to clear out a drop-down in some way. Maybe it clears "list-data."    
    
If you have any insights or links to documentation, that would be very helpful to me. I hate to leave behind code with documentation that basically says, "this works but I have no idea why."
    
Thank you.

posted by:   Steven White       5-Sep-2018/10:27:06-7:00



I think the most important thing to get about questions like this, is that the answers are not necessarily found in documentation, but in exploring the widgets with Rebol's built-in help. I changed the second drop-down label to 'ms' because I wanted a short label to type at the command line. I put a 'probe at the end of the load-subcat function, and then pressed the ESC key in the console, where I could explore the properties of the 'ms object:
    
? ms
    
That lists all the values, functions, etc. in the 'ms object. Then, you can see where the values are stored, experiment with the built-in functions, etc.
    
? ms/list-data
    
You can see the 'reset function in the 'access property.
    
I just took a few minutes to experiment. That's what I do any time I don't know exactly what to do in Rebol.

posted by:   Nick       5-Sep-2018/10:59:04-7:00



Good point. VID is an artifact of a past era and if we want to find out some things about it, we are on our own to study it. So I tried to encapsulate your above advice into my little VID reference in case others might find it helpful.
    
Thank you.
    
http://cobolrebol.com/pages/documentation/VIDforCOBOL.html#section-11


posted by:   Steven White       6-Sep-2018/9:06:07-7:00



Name:


Message:


Type the reverse of this captcha text: "r e t o o f"



Home