Calculate a value with a markdown button

Dear Community

does anyone has built a small button with a markdown field and when onclick with a small javascript calculation?

My Scenario:
I have a distance input field (integer) and onclick I need this distance calculated (result = distance * 0,35ct) and pasted into a travel-cost input field.

I do not know how to read and write those fields.
I searched in the DOM but there is no clear identifier for the input field.

any ideas?

Many thanks
Chris

Hello, I didn’t understand your question. Could you please describe in detail what features of NocoBase you are using and what configurations you are making?

Hello,

I have a normal form block for entering data in a table.
I have the following fields.

  • distance
  • travel-costs

In distance the user will enter the distance for a person. For example 150km
In travel costs they can manually enter a value in €. For example 200€ for a train ticket.

Now we have the situation that a person travelling by car can have a refund by kilomter. At the moment 0,35ct. But this value can change over time because of federal laws.

So what I want to build (and do not know how) is a small button / icon and with onclick I want to have the calculated travel costs (distance * 0,35) in the travel cost field.

Many thanks
Chris

Any ideas ?

May thanks
Chris

Hello,

Better to add a field to the Data table source that will be defined as a Formula.
Settings > Data sources > Your source > Your collection > Your table > Configure fields > +Add field > Formula

In this data column, you can define your expression, such as:

There are also an link to documentation and all posible syntaxes: https://docs.nocobase.com/handbook/calculation-engines/formula

After that, you can add this calculated column to your data block to show it to the users.

Regards,

Zdeněk