A newbie trying to understand Button Formulas

Hi, I’m very new to Coda and not yet sure how button formulas work (or most formulas for that matter :thinking:). Any help would be much appreciated :smiley:

Example Table

I want three buttons sitting above the table in the doc to do the following:

  • Press Button 1
  • the values in column B are updated to equal the values in column A. For example if I press Button 1, column B would update to show the value 5 where the value of column A was also 5

  • however, because Button 1 performs the action and thus column B does not have a formula itself, I could subsequently update the values in column B manually if I want to. For example I could change the value in column B from 5 to 7

  • Press Button 2
  • the values in column C are updated to equal their current value + the current value of column B. For example the value in row 1, column C would be equal to 120 + 7 i.e. 127
  • Press Button 3
  • clears all values from column B

  • note: could this Button be automated such that it is pressed automatically once the action from manually pressing Button 2 has been completed?

Does anyone have an example of a table and buttons they’ve created like this I can learn from?

HI Michael

Welcome to Coda! Hope that you will find it a wonderful tool.

I have created an example for you in the page Using buttons to Update tables in my doc.

You can also watch Maria explain buttons in the below video from the CohaHQ channel:

Happy non-coding
Piet

1 Like

Maybe just a clarification, clicking a button triggers and Action. That Action can execute a Formula.

You can use /button, or a button column, to use the non-coding version where the buttons will each trigger different formulas in the background, using the parameters you entere
d in the pop-up screen.

R
P

Hi @Michael_Bartholomew :blush: !

I’ve created a sample based on your description :blush:. (You’ll find it below)

But first, the explanations :innocent: .

In my sample, this is done with the very first button named Copy_Button.
Its Action formula is this one :

[Example Table].FormulaMap(
  RunActions(
    ModifyRows(
      CurrentValue,
      B,CurrentValue.A
    )
  )
)

And what it does is :

It takes the table [Example Table] and for each row in the table (FormulaMap()) it runs this action (RunActions()) :point_right: ModifyRows() :

  • The row to modify here is represented by CurrentValue
    A table is in fact a list of rows and each row in the list of all rows is stored within CurrentValue. Each very specific value in your column C (for example) is stored as CurrentValue.C which Coda would display as just C in a formula)
  • The column to modify is the column B ( CurrentValue.B)
    In other words, each specific value in the column B
  • The new column value is CurrentValue.A
    I.e.: Each specific value in the “list of all rows” in the column A

Now for the buttons 2 and 3, they work in a similar way as the button 1 does :blush:

It can be done, but you’ll need to set up your Button 3 before the Button 2 in order to use it in the Action formula of the Button 2.

In the Button 3 (named Clear_Button in my sample) the Action formula looks like this :

[Example Table].FormulaMap(
  RunActions(
    ModifyRows(
      CurrentValue,
      B,""
    )
  )
)

Kind of the same as the Button 1 but this time, it acts on B (CurrentValue.B) and replace each specific value in the column B by "" (Blank) :blush: .

And for the Button 2 (named Sum_Button)

RunActions(
[Example Table].FormulaMap(
  RunActions(
    ModifyRows(
      CurrentValue,
      C,C + B
    )
  )
),
Clear_Button)

This one runs 2 distinctive actions :

  1. For each row in your table, it sums each specific value in the column C and each specific value in the column B (and the results appear for each row in the column C)

And then

  1. It pushes the Button 3 (the Clear_Button) :blush:

This is not easy to explain (or to understand for that matter :sweat_smile:)… So, don’t hesitate, if you need more explanations :innocent: .

In the meantime, I hope this helps :innocent: !

PS: Oh and there’s a topic I created a while ago which helped me a lot with FormulaMap() (as I was stuck with this one :innocent: ):

1 Like

Hello @Piet_Strydom ,

this is a nice solution so I thank you for your time. Alas, the solution presented by @Pch is pretty much exactly what I was looking for.

However it is nice to see and learn how ideas can be implemented in different ways which gives people more options / flexibility.

Thanks again for your help.

Regards,

Michael.

2 Likes

Hi @Pch ,

this solution is exactly what I was looking for, so thank you.

I now have a much greater understanding of how formulas work and I previously had no idea about FormulaMap() so this has been an eye opener and a huge help.

I still have a lot to learn but this solution allows me to fulfil my current needs. Thank you for providing such detail.

Regards,

Michael.

1 Like

No problem, Michael.

That is the beauty of Coda, many different ways to do things, so you are always learning.

In a subtle way, @Pch and I solved slightly different problems. One solution is to be able to execute specific single rows, the other to do the calculation for the entire table in a single button press.

Elsewhere i have seen a solution using FormulaMap() that will update rows based on a certain characteristic in another row. I am certain that demo was also done by PcH.

regards
Rambling Pete.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.