# Proposal: Introduce emptyIf for Conditional Output

**URL:** <https://forums.realmacsoftware.com/t/proposal-introduce-emptyif-for-conditional-output/52447>\
**Category:** Elements\
**Created:** [November 15, 2025, 11:44am UTC](https://forums.realmacsoftware.com/t/proposal-introduce-emptyif-for-conditional-output/52447 "2025-11-15T11:44:40Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Doobox](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/doobox/32/32373_2.png) [@Doobox](https://forums.realmacsoftware.com/u/Doobox)\
**Post date:** [November 15, 2025, 11:44am UTC](https://forums.realmacsoftware.com/t/proposal-introduce-emptyif-for-conditional-output/52447/1 "2025-11-15T11:44:41Z")

</div>

@ben @dan

Further to my idea to simplify control group creation with states. After giving it a lot of thought here is my proposal.

I would like to propose a small but powerful enhancement to the control schema: the addition of a new conditional key named **`emptyIf`**.

This feature would significantly simplify component development, reduce duplication, and make the system more scalable for state-based control groups.

**What is `emptyIf`?**

I propose adding a new optional schema key:

```json
“emptyIf”: “condition”

```

It functions similarly to your existing:

- `visible`

- `enabled`

…using the same expression system and evaluation context.

However, instead of affecting UI visibility or interactivity, **`emptyIf` affects the value a control returns**.

### **Behavior**

When `emptyIf` evaluates to `true`, the control should return an empty string (`""`) during output generation.

This does **not** hide the control in the UI  
and does **not** disable it.

It simply prevents the control from contributing to any final output in rw.props.

# **Why this matters for developers like me**

Groups of controls can exist in multiple states.  
Different states naturally require different output patterns.

Today, any component that needs to assemble output from a group of controls must also:

- replicate portions of the group’s internal state logic

- understand which controls are applicable in which situations

- handle conditions that already exist in the schema

- manually skip controls based on state-dependent logic

This results in:

- **logic duplication**

- **hard-to-maintain code**

- **greater likelihood of mismatches**

- **increased fragility when the platform evolves**

By allowing controls to self-declare when they should “fall silent,” the system becomes **far easier for developers to reason about** , especially for complex, multi-state control groups.

**How `emptyIf` improves extensibility**

### ✔ Keeps logic in one source of truth

Currently, the schema already knows all the conditions.  
But hooks must re-express some of those conditions.

`emptyIf` lets the schema express the final piece:  
**“In this state, this control should not produce output.”**

Components then don’t need duplicated state machines.

✔ Drastically simplifies javascript

With `emptyIf` in place, a hooks js can generate macros / compiled attributes by simply:

```javascript
result = allControlOutputs.filter(Boolean).join(" ");

```

No conditionals.  
No branching logic.  
No state replication.

### ✔ Safe, backward-compatible enhancement

- Existing controls remain unchanged

- Existing hooks logic continues to work

- Developers who don’t need this feature can ignore it

- Component authors who want cleaner output logic can adopt it

Example (generic)

```json
{
  "id": "exampleControl",
  "format": "example-{{value}}",
  "visible": "mode != 'off'",
  "emptyIf": "mode == 'off'"
}

```

This pattern is extremely useful when a group has multiple states where some controls become invisible and should not influence output.

# **Summary of Benefits**

- Removes state-duplication from hooks

- Reduces inconsistencies between schema logic and hooks logic

- Produces cleaner, more maintainable components

- Increases flexibility for future control types

- Keeps the system declarative and predictable

- Requires minimal change to your existing schema system

- Delivers a large benefit for a small implementation cost

---

<div class="post-metadata">

**Author:** ![Doobox](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/doobox/32/32373_2.png) [@Doobox](https://forums.realmacsoftware.com/u/Doobox)\
**Post date:** [November 15, 2025, 2:35pm UTC](https://forums.realmacsoftware.com/t/proposal-introduce-emptyif-for-conditional-output/52447/2 "2025-11-15T14:35:47Z")

</div>

And a real world example of a much simplified hooks.js if emptyIf were implemented.

for two complex groups with multiple complex possible states, the js can be much simplified.

```javascript
// List all id's that I know will possibly return a useful value or "" for each group

const BG_GROUP_IDS = [
  "globalBgGradientFromColor",
  "globalBgGradientToColor",
  "globalTextColor",
  "globalTextColorOpacity",
  // etc...
];

const BORDER_GROUP_IDS = [
  "globalBorderWidth",
  "globalBorderColor",
  // etc...
];

function buildMacro(props, ids) {
  return ids
	.map((id) => props[id])
	.filter((v) => typeof v === "string" && v.trim() !== "")
	.join(" ")
	.trim();
}

const transformHook = (rw) => {
  const p = rw.props;

  // Expose the macro to the template
  rw.setProps({
	node: rw.node,
	globalBgMacro: buildMacro(p, BG_GROUP_IDS),
	globalBorderMacro: buildMacro(p, BORDER_GROUP_IDS),
  });
};

exports.transformHook = transformHook;

```

---

<div class="post-metadata">

**Author:** ![handshaper](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/handshaper/32/27373_2.png) [@handshaper](https://forums.realmacsoftware.com/u/handshaper)\
**Post date:** [November 15, 2025, 7:34pm UTC](https://forums.realmacsoftware.com/t/proposal-introduce-emptyif-for-conditional-output/52447/3 "2025-11-15T19:34:39Z")

</div>

Yes, please!

---

<div class="post-metadata">

**Author:** ![Doobox](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/doobox/32/32373_2.png) [@Doobox](https://forums.realmacsoftware.com/u/Doobox)\
**Post date:** [November 16, 2025, 12:12pm UTC](https://forums.realmacsoftware.com/t/proposal-introduce-emptyif-for-conditional-output/52447/4 "2025-11-16T12:12:21Z")

</div>

Bug in current “enabled” key as well.

Currently does nothing. Does not hide the control when evaluated, and does not disable the control from user input. Does not stop value getting to rw.props if thats what this was meant to do, like I proposed for emptyIf?

```json
{
  "groups": [
    {
      "title": "Tester",
      "properties": [
        {
          "title": "Mode",
          "id": "mode",
          "segmented": {
            "items": [
              {
                "value": "enabled",
                "title": "Enabled",
                "default": true
              },
              {
                "value": "disabled",
                "title": "Disabled"
              }
            ]
          }
        },
        {
          "title": "Number",
          "id": "myNumber",
          "enabled": "mode == 'enabled'",
          "number": {
            "default": 100,
            "subtitle": "a simple number input"
          }
        }
      ]
    }
  ]
}

```

---

<div class="post-metadata">

**Author:** ![ben](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/ben/32/28488_2.png) [@ben](https://forums.realmacsoftware.com/u/ben)\
**Post date:** [November 16, 2025, 2:14pm UTC](https://forums.realmacsoftware.com/t/proposal-introduce-emptyif-for-conditional-output/52447/5 "2025-11-16T14:14:49Z")

</div>

Hi @Doobox

Thanks for taking the time to propose this, it’s great to see developers asking for improvements to the Elements APIs 😃

All of us have read your proposal and we are going to consider it internally before we make any snap decisions on adding to the property control API.

Honestly, the chatgpt-ified proposal has made the proposal harder for me to understand as there’s a lot of information, especially for what I think is a simple request.

In short, and if I am understanding you correctly, you want to stop having to do a conditional check in the hooks.js file before returning (or not) other control values.

So, currently you’d have to do this:

```javascript
const transformHook = (rw) => {
    const {
        // colorType is the control that sets the type of color the user wants,
        // in this example it would be either 'solid' or 'gradient'
        // colorType would be used to show/hide other controls
        // via the `visible` prop in properties.json
        colorType,
        
        // These three props are conditional, and should/shouldn't
        // be used based on the value of colorType
        colorBgSolid,
        colorBgGradientFrom,
        colorBgGradientTo
    } = rw.props;

    // Check colorType, return the appropriate classes
    const colorClasses = colorType === 'solid'
      ? colorBgSolid
      : `${colorBgGradientFrom} ${colorBgGradientTo}`

    rw.setProps({ colorClasses });
};

exports.transformHook = transformHook;

```

and instead, you’d like to do this:

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

    // all three of these controls have the new `emptyIf` property
    const { colorBgSolid, colorBgGradientFrom, colorBgGradientTo } = rw.props;

    // no need to check colorType each prop will
    // either have a value, or be empty, based on the new `emptyIf` property
    const colorClasses = [
        colorBgSolid,
        colorBgGradientFrom,
        colorBgGradientTo
    ].join(" ");

    rw.setProps({ colorClasses });
};

exports.transformHook = transformHook;

```

Is that basically what you’re asking for? If not, can you give us a concrete code example of what you’re currently having to do, and what you’d like to do instead.

Thanks 🙂

---

<div class="post-metadata">

**Author:** ![Doobox](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/doobox/32/32373_2.png) [@Doobox](https://forums.realmacsoftware.com/u/Doobox)\
**Post date:** [November 16, 2025, 2:21pm UTC](https://forums.realmacsoftware.com/t/proposal-introduce-emptyif-for-conditional-output/52447/6 "2025-11-16T14:21:43Z")

</div>

> [@ben](#):
>
> ```auto
> const transformHook = (rw) => {
> 
> // all three of these controls have the new `emptyIf` property
> const { colorBgSolid, colorBgGradientFrom, colorBgGradientTo } = rw.props;
> 
> // no need to check colorType each prop will
> // either have a value, or be empty, based on the new `emptyIf` property
> const colorClasses = [
> colorBgSolid,
> colorBgGradientFrom,
> colorBgGradientTo
> ].join(" ");
> 
> rw.setProps({ colorClasses });
> };
> 
> exports.transformHook = transformHook;
> 
> ```

Exactly, yes.

So yes

// each prop will either have a value, or be empty, based on the new `emptyIf` property.

We can then do with that what we will.

Re broken “enabled” key. Might be with considering just using that key for this purpose, as its currently broken, so no one can be using it 🤷‍♂️ Unless you really intended and want enabled to simply disable user input on any given control.

---

<div class="post-metadata">

**Author:** ![ben](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/ben/32/28488_2.png) [@ben](https://forums.realmacsoftware.com/u/ben)\
**Post date:** [November 16, 2025, 2:26pm UTC](https://forums.realmacsoftware.com/t/proposal-introduce-emptyif-for-conditional-output/52447/7 "2025-11-16T14:26:05Z")

</div>

> [@Doobox](#):
>
> Exactly, yes.

Great, now I fully understand what we’re aiming for 😃

> [@Doobox](#):
>
> enabled” key. Might be with considering just using that key for this purpose

That might be an option, and it’s why we need to consider what/how/if we proceed with this `emptyIf` proposal before making any snap decisions.

I’ll add a ticket for us to look in to this further 🙂

---

<div class="post-metadata">

**Author:** ![ben](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/ben/32/28488_2.png) [@ben](https://forums.realmacsoftware.com/u/ben)\
**Post date:** [November 16, 2025, 2:36pm UTC](https://forums.realmacsoftware.com/t/proposal-introduce-emptyif-for-conditional-output/52447/8 "2025-11-16T14:36:07Z")

</div>

also, just a thought off the top of my head (this might not work, or be doable)…

what if we had `disabledValue` instead?

You could set the value of a disabled control to an empty string, `false`, or perhaps a tailwind class… that might make this more flexible for all of us 😃

---

<div class="post-metadata">

**Author:** ![Doobox](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/doobox/32/32373_2.png) [@Doobox](https://forums.realmacsoftware.com/u/Doobox)\
**Post date:** [November 16, 2025, 2:41pm UTC](https://forums.realmacsoftware.com/t/proposal-introduce-emptyif-for-conditional-output/52447/9 "2025-11-16T14:41:06Z")

</div>

> [@ben](#):
>
> disabledValue

That would be way better and more flexible. Cant think off the top of my head what else I’d like to return for “disabledValue” other than ““ but I’d bet it will be a godsend one day.

It was going to be my proposal, but didn’t want to push my luck, so went for the lesser option 😂

---

<div class="post-metadata">

**Author:** ![MichaelDroste](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/michaeldroste/32/37212_2.png) [@MichaelDroste](https://forums.realmacsoftware.com/u/MichaelDroste)\
**Post date:** [November 16, 2025, 4:03pm UTC](https://forums.realmacsoftware.com/t/proposal-introduce-emptyif-for-conditional-output/52447/11 "2025-11-16T16:03:56Z")

</div>

Thanx for contributing - didn’t know you could specify commands - new to me - thought there were basic established computer commands and that was it…

---

<div class="post-metadata">

**Author:** ![Doobox](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/doobox/32/32373_2.png) [@Doobox](https://forums.realmacsoftware.com/u/Doobox)\
**Post date:** [November 16, 2025, 4:23pm UTC](https://forums.realmacsoftware.com/t/proposal-introduce-emptyif-for-conditional-output/52447/12 "2025-11-16T16:23:08Z")

</div>

Those aren’t ‘commands’, they’re just keys you can invent for a JSON structure. JSON is only a data format, so you can create any keys you want as long as the software that reads it knows what they mean. Elements in this case.

---

<div class="post-metadata">

**Author:** ![Doobox](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/doobox/32/32373_2.png) [@Doobox](https://forums.realmacsoftware.com/u/Doobox)\
**Post date:** [November 16, 2025, 4:45pm UTC](https://forums.realmacsoftware.com/t/proposal-introduce-emptyif-for-conditional-output/52447/13 "2025-11-16T16:45:28Z")

</div>

Now I’m pushing my luck 😂  
But would be very neat to extent the current “format” key.

```json
"format": {
    "value": "opacity-[{{value}}%]",
    // Optional
    "disabled": {
        "condition": "someControl == 'theValueToCheck'",
        "value": ""
    }
}

```

Maybe a bit late in the day for that for backward compatibility.

---

<div class="post-metadata">

**Author:** ![MichaelDroste](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/michaeldroste/32/37212_2.png) [@MichaelDroste](https://forums.realmacsoftware.com/u/MichaelDroste)\
**Post date:** [November 16, 2025, 6:37pm UTC](https://forums.realmacsoftware.com/t/proposal-introduce-emptyif-for-conditional-output/52447/14 "2025-11-16T18:37:18Z")

</div>

Keys commands potato tomato 🙂 lol 😂

I thought it was ‘all figured out’ in 2025

That there couldn’t be new keys…

Very interesting thread…

Did you get a degree in computer science?

They say many musicians would be good coders and good at video editing… similar brain types….

---

<div class="post-metadata">

**Author:** ![Doobox](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/doobox/32/32373_2.png) [@Doobox](https://forums.realmacsoftware.com/u/Doobox)\
**Post date:** [November 16, 2025, 6:41pm UTC](https://forums.realmacsoftware.com/t/proposal-introduce-emptyif-for-conditional-output/52447/15 "2025-11-16T18:41:32Z")

</div>

> [@MichaelDroste](#):
>
> Did you get a degree in computer science?

Carpentry (city & guilds) 😄

---

<div class="post-metadata">

**Author:** ![Doobox](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/doobox/32/32373_2.png) [@Doobox](https://forums.realmacsoftware.com/u/Doobox)\
**Post date:** [November 16, 2025, 6:42pm UTC](https://forums.realmacsoftware.com/t/proposal-introduce-emptyif-for-conditional-output/52447/16 "2025-11-16T18:42:38Z")

</div>

The day job:

> **[Gary Simpson Jersey Carpenter](https://www.garysimpson.co.uk)**
>
> Trusted carpenter in Jersey, Channel Islands with over 30 years of experience delivering premium-quality workmanship for residential and commercial clients.

---

<div class="post-metadata">

**Author:** ![upssjw](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/upssjw/32/26063_2.png) [@upssjw](https://forums.realmacsoftware.com/u/upssjw)\
**Post date:** [November 16, 2025, 6:44pm UTC](https://forums.realmacsoftware.com/t/proposal-introduce-emptyif-for-conditional-output/52447/17 "2025-11-16T18:44:16Z")

</div>

excellent work/quality from photos, nice

---

<div class="post-metadata">

**Author:** ![Doobox](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/doobox/32/32373_2.png) [@Doobox](https://forums.realmacsoftware.com/u/Doobox)\
**Post date:** [November 16, 2025, 6:44pm UTC](https://forums.realmacsoftware.com/t/proposal-introduce-emptyif-for-conditional-output/52447/18 "2025-11-16T18:44:34Z")

</div>

Been off work a few weeks with a knackered knee, hence my bugging ben and dan daily 😂

---

<div class="post-metadata">

**Author:** ![MichaelDroste](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/michaeldroste/32/37212_2.png) [@MichaelDroste](https://forums.realmacsoftware.com/u/MichaelDroste)\
**Post date:** [November 16, 2025, 6:57pm UTC](https://forums.realmacsoftware.com/t/proposal-introduce-emptyif-for-conditional-output/52447/19 "2025-11-16T18:57:07Z")

</div>

Got to ask, where did you learn programming?

How long have been doing this?

---

<div class="post-metadata">

**Author:** ![Doobox](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/doobox/32/32373_2.png) [@Doobox](https://forums.realmacsoftware.com/u/Doobox)\
**Post date:** [November 16, 2025, 7:01pm UTC](https://forums.realmacsoftware.com/t/proposal-introduce-emptyif-for-conditional-output/52447/20 "2025-11-16T19:01:54Z")

</div>

Just sort of picked up web dev about 15 years ago , much the same as a lot of guys are doing here. Always wanted to get into app dev, but Obj-C language at the time just wouldn’t click for me.  
Then Swift followed by SwiftUI came along and it just felt intuitive.

---

<div class="post-metadata">

**Author:** ![MichaelDroste](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/michaeldroste/32/37212_2.png) [@MichaelDroste](https://forums.realmacsoftware.com/u/MichaelDroste)\
**Post date:** [November 16, 2025, 7:10pm UTC](https://forums.realmacsoftware.com/t/proposal-introduce-emptyif-for-conditional-output/52447/21 "2025-11-16T19:10:10Z")

</div>

Want to do my trumpet app lol 😆

I started version 1 got the graphics done ✅ then hired the same person to program version 1 - 2 and 3

I’m debating trying chat gpt - I tried to redo version 3 rewriting one section would break another… did this for 3-4 days

Deleted the results.

Chat GPT is telling me now that starting from scratch- new libraries etc… would be a breeze and take a few hours..

I doubt it - but that’s what it is saying…

[Next page](https://forums.realmacsoftware.com/t/proposal-introduce-emptyif-for-conditional-output/52447.md?page=2)
