Deep modification of control objects [Back to index]
Disclaimer: deep modification is extremely unstable. Make sure you implemented all fail-safe procedures and created a backup of your document before using it.
Note that all information in this post has been gathered by analyzing source code, deduction and trial-and-error. This means it is highly probable that some parts are inaccurate or just simply wrong.
Format of control objects
Each control object is actually a standard object with a few special flags. However, whenever you reference a “button”, “select” or any other control column, the result isn’t the whole object, but only it’s value
property.
Hidden formulas (such as Button()
) allow you to insert the full object, so it renders properly in other columns.
By putting such an object inside of a _Merge()
function, you can convert it from a control object into a normal object and view its structure.
And by adding +""
to the formula, it converts into pure json.
(Result has been formatted using json beautifier)
You can convert json string back into an object using ParseJSON()
. However, this formula converts the output into a standard object, and not a control object. This means that instead of rendering the button, it will display its inner structure.
In order to display it properly you need to wrap it with any kind of property. This works because a preview of an object is its first property and control objects inside of a standard object aren’t flagged to display as structure.
The resulting formula looks like this:
And, in case of a button, creates a functioning control.
There are however some differences because this isn’t a control object, but rather a standard object containing a control object.
The most notable is the box that displays on hover.
This can be easily fixed by putting the control into a button label.
Edit:
Since nested buttons are no longer supported there is currently no way (that I know of) to hide this on-hover box.
Why would you need that?
Everything above results in a slightly worse version of a the same button.
However, in the process we gain access to the pure json string which we can then modify.
By adding a string as a second argument for the _Merge()
function you can change different properties of the resulting control object.
Example usage: dynamic buttons
This can be used to change button formula without the need to create a button column for each button.
In addition to leaving less clutter and being less tedious, this allows to dynamically modify amount of buttons in any formula.
Button action is saved as an array of actions in properties --> actionValues
.
Adding ParseJSON('{"properties": {"actionValues":"_7_"}}')
as a second parameter in _Merge
overwrites that value with a _7_
. Now you can use Substitute
to replace it with "[" + _Merge(Action) + "]"
. (Don’t forget about adding the []
, your doc will crash without them)
You have to use substitute instead of putting your action directly into the _Merge
function, for unknown reasons putting it directly won’t work.
The formula should look something like this:
You can even put it in a loop and make every button do something different.
Here you have an example how to implement that: