how to add text at runtime to text from a text_field

I’m trying to add an addendum note to a text_field IF a column has a specific value.

 	if(columnX='3'){
		elements.text_field == text_field + ': (addendum note)';
}

So if columnX is any number other than 3 then the text_filed should display the value from the database only.

Thanks,
Bob

Hi:

I think you’re changing the signs “=”:
= → Assignation.
== → Comparation.

Modify your code by:

if(columnX=='3'){
      elements.text_field = text_field + ': (addendum note)';
}

Greetings.

Thanks Adel,

After reversing the = and == I now get

“assignment to read only property”

and the addendum note not added?
The only thing I’ve fond on this message is that it may be a bug?

Hi Bob,

you’re trying to add text to the element itself, that’s what causing the error.
In case this element ‘text_field’ is a label you could use the property text (so: element.text_field.text) to add text.

But I get the feeling things are different, so let’s get things straight:

you’re talking about an element ‘elements.text_field’ what type of element is this (text_field/text_area/label) AND what dataprovider is attached.
You’re also referencing ‘text_field’, assuming this is a dataprovider.

So what are you trying to accomplish?

  1. adding text temporarily to a text you retrieved from the database
  2. adding text to the text that’s already in the dataprovider?

Marc,
What I’m trying to accomplish is to add temporarily add text to a text_field that is displaying data from a column in a database.

In your suggestion “element.text_field.text” the “.text” is not an option.
I guess my question should be - how to display the text of the element and temporarily add additional text based on the condition on “columnX”?

Thanks,
Bob

Thank you everyone - I figured it out.

I needed a calculation that would add the addendum note

function is_postOpOnly()
{
	if(columnX=='3'){
		return text_field + ' (: addendum note)';
}else{
		return text_field;
}}

then change the data provider to be the calculation not the database column.

Hi Bob,

In general you can’t change data in form fields. You change it in their data providers which means you will actually be changing the stored data (when using table columns).
This also means that you can’t really use fields on a form without a data provider, or to be more precise it would be useless since you can’t do much with it.
So to do non-destructive changes to data for display purposes only you can use (un-stored) calculations (like you already figured out) or use form- or global variables as a data provider.

Hope this helps.