I have been attempting to put together a Map transform with an expression output that is using an if statement to change color if TRUE, and shouldn't change the color at all if FALSE. However, due to the requirement of needing both a TRUE and a FALSE statement is messing me up since null and ' ' both don't end up keeping the color the same.
Is there a way that I can remove the need for a FALSE statement or bypass it?
No. Bindings must return a value. There's no "skipping" the final assignment of the return value to the target property.
I do this often and just return an empty string when I don't want the result to override existing styling. I tend to prefer expression transform over map transform (IF or CASE/SWITCH)
I have yet to find an instance where an empty string value on a CSS/Style property does anything to modify/impact the existing styling.
if({value}, "red", "")
This only works if there is an appropriate default style in that prop. The OP appears to want the original value of the prop to remain.
I see, he wants to retain the previous value for the property, not just inherit whatever styling is inheritable.
@pascal.klimes, is that so? Can you post more detail regarding what you are trying to achieve (and more importantly why). I suspect there is an alternative approach/solution.
Consider just returning {value} when false.
Only if your transform is being applied to a valid color value (e.g. {value} = "blue"). I'm not sure there are real use cases for applying a transform to a color value based on another color value.
I assumed OP was implementing a transform to some other binding/expression that evaluated as true or false, justifying an IF expression. If he is trying to return a color then settings color to True/False by returning {value} is not valid.
One other option to retain existing property value, is not to apply the binding directly on the property you are targeting but instead on some other (custom) property and include a script transform on the custom property that will conditionally write a value to the targeted property or not (leaving it without change).
I'm saying you can, not that you should. More detail is required for a recommended solution.
I briefly (just for arguments sake) entertained the notion of using an expression structure binding on a property and passing that property's own current value in as part of the structure so you could return it as one of the conditional paths. In practice (I tried) that does not work, returns null when any other value in the structure is changed externally. In theory it could work but with circular referencing its a bad idea. One that IA developers likely look for and actively block, possibly by substituting a NULL value
.
I've gone down a bit of a rabbit hole.
If appears that you can reference a property's current value and even return that value (retaining the original value) in a script transform. Not that you should, but you can without risking circular references.
def transform(self, value, quality, timestamp):
self.custom.backup = self.custom.color
if value > 10:
return "red"
else:
# Return this property's own current value
return self.custom.color