# Dropzone Control from a Dropdown

**URL:** <https://forums.realmacsoftware.com/t/dropzone-control-from-a-dropdown/44214>\
**Category:** Elements API\
**Created:** [August 11, 2024, 2:04am UTC](https://forums.realmacsoftware.com/t/dropzone-control-from-a-dropdown/44214 "2024-08-11T02:04:12Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bill](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/bill/32/107_2.png) [@Bill](https://forums.realmacsoftware.com/u/Bill)\
**Post date:** [August 11, 2024, 2:04am UTC](https://forums.realmacsoftware.com/t/dropzone-control-from-a-dropdown/44214/1 "2024-08-11T02:04:12Z")

</div>

I’m trying to control whether a dropzone is shown or not, based on a dropdown selection value:

```auto
@if(mydropdownlist == "a")
  @dropzone("child1")
@endif

```

I’m not even sure if a dropdown control exists yet, but it definitely will be needed for other things besides this example.

This use-case is selecting child templates to use - similar to right-clicking on the plus button in the edit window in Stacks. Not sure if you are going to provide the same control in the edit window for selection or have people use a dropdown control?

---

<div class="post-metadata">

**Author:** ![dan](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/dan/32/28516_2.png) [@dan](https://forums.realmacsoftware.com/u/dan)\
**Post date:** [August 12, 2024, 2:24pm UTC](https://forums.realmacsoftware.com/t/dropzone-control-from-a-dropdown/44214/2 "2024-08-12T14:24:13Z")

</div>

Hey @Bill,

Yes, we have a dropdown menu… it was missing from the docs, the [page is here now](https://docs.realmacsoftware.com/elements-docs/elements-language/properties.json/ui-controls/select). Anything you see used in our Components is available as we use the same API ☺

Here’s an example of a dropdown menu (or Select as we call it) to pick your favorite fruit…

```auto
{
          "title": "Fuit",
          "property": "fruitydropdown",
          "select": {
            "default": "apple",
            "items": [
              {
                "value": "apple",
                "title": "Green Apple"
              },
              {
                "value": "orange",
                "title": "Orange"
              },
              {
                "value": "lemon",
                "title": "Yellow Lemon"
              },
              {
                "value": "pear",
                "title": "Pear"
              }
            ]
          }
        },

```

@tpbradley is making a few changes to how the If statement works, he’ll follow up shortly with how to do things — Hang in there!

_P.S. I’m wondering what you’re cooking up and if it’s worth a quick video chat with us so we can help answer any questions you might have. Let me know if you’re interested and we could set something up one afternoon this week._

---

<div class="post-metadata">

**Author:** ![Bill](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/bill/32/107_2.png) [@Bill](https://forums.realmacsoftware.com/u/Bill)\
**Post date:** [August 12, 2024, 10:21pm UTC](https://forums.realmacsoftware.com/t/dropzone-control-from-a-dropdown/44214/3 "2024-08-12T22:21:36Z")

</div>

@dan Yes, I sent you an email re: questions - hopefully you got it.

Thanks,

Bill  
Stack-Its

---

<div class="post-metadata">

**Author:** ![dan](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/dan/32/28516_2.png) [@dan](https://forums.realmacsoftware.com/u/dan)\
**Post date:** [August 12, 2024, 10:49pm UTC](https://forums.realmacsoftware.com/t/dropzone-control-from-a-dropdown/44214/4 "2024-08-12T22:49:15Z")

</div>

Got it, will drop you a reply tomorrow (Tuesday) 👍

---

<div class="post-metadata">

**Author:** ![tpbradley](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/tpbradley/32/25503_2.png) [@tpbradley](https://forums.realmacsoftware.com/u/tpbradley)\
**Post date:** [August 13, 2024, 6:01pm UTC](https://forums.realmacsoftware.com/t/dropzone-control-from-a-dropdown/44214/5 "2024-08-13T18:01:41Z")

</div>

Hey @Bill,

I’ve put together a project with a custom element showing how to use switch and select controls to conditionally show content in the HTML.

> **[Switches.elements.zip](https://wetransfer.com/downloads/41e705191376ba58d028e7590b31b24420240813175714/40e6da)**
>
> 1 file sent via WeTransfer, the simplest way to send your files around the world

The main take away is that business logic like string comparisons should be performed in the hooks file, then within the template you perform simple bool checks. This helps to keep templates simple and focused on HTML rather than containing complex conditional logic.

For example, say you have this select control in the properties config

```auto
{
    "title": "Select",
    "property": "select",
    "responsive" : false,
    "select": {
        "default": "apple",
        "items": [{
            "value": "apple",
            "title": "Apple"
        }, {
            "value": "pear",
            "title": "Pear"
        }]
    }
}

```

Your hooks file could check some string values and set a couple of flags accordingly

```auto
const transformHook = (rw) => {

    // Extract the select property
    const { select } = rw.props;

    // Perform string comparisons and provide the template with simple bool values
    rw.setProps({
        showApple : select == "apple",
        showPear : select == "pear"
    });
}

exports.transformHook = transformHook;

```

Then, within the template you just need a few simple if statements

```auto
@if(showApple)
    🍎
@elseif(showPear)
    🍐
@endif

```

Hope this helps

---

<div class="post-metadata">

**Author:** ![Bill](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/bill/32/107_2.png) [@Bill](https://forums.realmacsoftware.com/u/Bill)\
**Post date:** [August 13, 2024, 10:08pm UTC](https://forums.realmacsoftware.com/t/dropzone-control-from-a-dropdown/44214/6 "2024-08-13T22:08:44Z")

</div>

Ok Tom, thanks for the example. I’m still trying to dig through all the example stuff in there, but there’s two things that are really bugging me:

- You said in the component that ‘non-responsive switch controls can be used in ‘if’ statements’. I believe what you are really saying is it expects booleans to work properly w/ screensizes. If that’s the case, could you please consider changing **responsive** to **true** for any switches using screensize prefixes. This would make a lot more sense to us developers, as that would be what we normally will be doing. If need a string for some odd reason then set responsive to false.

- You have been setting const like this:  
‘const { select } = rw.props;’ - This is really an unintuitive way to write this. If I was going for a control value named ‘select’ , this is much easier to understand: ‘ **const select = rw.props.select;** ’  
NOTE: when using the old way, when paired w/ gallery or anything that will contain huge json arrays & looping through stuff, my computer w/ 40GB of RAMM was nearly brought to it’s knees (when using my way, it barely even blinked when updating)

Thanks, Bill

---

<div class="post-metadata">

**Author:** ![tpbradley](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/tpbradley/32/25503_2.png) [@tpbradley](https://forums.realmacsoftware.com/u/tpbradley)\
**Post date:** [August 14, 2024, 9:12am UTC](https://forums.realmacsoftware.com/t/dropzone-control-from-a-dropdown/44214/7 "2024-08-14T09:12:25Z")

</div>

> [@Bill](#):
>
> could you please consider changing **responsive** to **true** for any switches using screensize prefixes.

We spoke at great length internally about this. It’s was a tricky call but while developing the built in components, we found that out of 130 ish switches, only 10 were non-responsive.

I realise that when other developers build components they may need the majority of switch to be non-responsive, but as Elements is primarily a front end Tailwind builder it made sense to be responsive first.

> [@Bill](#):
>
> You have been setting const like this:  
> ‘const { select } = rw.props;’ - This is really an unintuitive way to write this.

This is modern JS syntax and can really help to tidy up code, consider the following.

```auto
const select = rw.props.select;
const switch = rw.props.switch;
const button = rw.props.button;
const text = rw.props.text;

// Becomes
const {select, switch, button, text} = rw.props;

```

You can read more about it here [JavaScript Destructuring](https://www.w3schools.com/js/js_destructuring.asp)

> [@Bill](#):
>
> my computer w/ 40GB of RAMM was nearly brought to it’s knees

I’d love to get a copy of the project file and run some tests, would you be able to send it to [support@realmacsoftware.com](mailto:support@realmacsoftware.com)

Cheers

---

<div class="post-metadata">

**Author:** ![Bill](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/bill/32/107_2.png) [@Bill](https://forums.realmacsoftware.com/u/Bill)\
**Post date:** [August 15, 2024, 2:49am UTC](https://forums.realmacsoftware.com/t/dropzone-control-from-a-dropdown/44214/8 "2024-08-15T02:49:10Z")

</div>

@tpbradley Hi Tom,

Ok, I incorporated the select-to-if statement method ok.

I tried again to get gallery & console.logs logs to bog things down, but doesn’t seem to be choking, maybe you tweaked something in the last beta.

I still like dot notation & code clarity is key when I look at something 6 months later - otherwise there’s hell to pay to figure out what is going on.

I still am having problems with @ text not injecting back into the same place & mutating multiple sets of new p tags, default/previously set @ text in other if statements aren’t showing in the edit window based on what is chosen in a select (text is there but just white text at the moment;) and I need something similar to an @ text but for html/markup but without the wrapping p tag. I don’t know if that makes sense or should we take a look at this stuff privately?

Thanks, Bill

---

<div class="post-metadata">

**Author:** ![dan](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/dan/32/28516_2.png) [@dan](https://forums.realmacsoftware.com/u/dan)\
**Post date:** [August 15, 2024, 2:39pm UTC](https://forums.realmacsoftware.com/t/dropzone-control-from-a-dropdown/44214/9 "2024-08-15T14:39:05Z")

</div>

> [@Bill](#):
>
> I don’t know if that makes sense or should we take a look at this stuff privately?

That would be great, have just dropped you an email…
