Concatenate values from a repeat into a single variable

In a form I have a repeat that outputs several results (they happen to be single sentences) from a serverConnect Server Action. Typically there could be anything from 3 to 12 sentences.
My aim is to put these sentences into a Medium Editor Textarea so they can be edited by the user and uploaded to a single database field.

The only way I can think of doing this is to add a variable before the repeat. Then inside the repeat put a {{var_comment.setValue(commpara_text)}} BUT I only get one of the paras in the variable. How can I concatenate the sentences?

In other languages I have used things like += “concatenate to the existing value” and not to overwrite.

This variable can then be used in the Medium Editor Textarea using something like
dmx-bind:value="var_comment.value"

Maybe I am overthinking this but I just can’t get anything to work, please help.

This needs to be client side as the result of the repeat is determined by user selection in the form.
I am working in SPAs

You don’t need a variable - as a dynamic value for your textarea select your query as an expression, and apply the Values formatter:

Then select the property(column name) you need to list there. This will add all the records returned by the query in your medium editor.

Hi @Teodor, I didn’t know that before and yes that will be useful in other areas.

Unfortunately that doesn’t solve this issue. I don’t want all the values returned by the query (B), I only want those that are shown in the repeat (A) ie lines 4, 9 and 14 in the example below.

and the code in Wappler

I hope this makes sense.

You say that:

But your repeat A uses the same expression/query as repeat B?
Or do you want to use anything else in the medium editor, and not the repeat?

You are right it does. The ‘code’ within the repeat determines which paragraphs to show. I tried using the same ‘code’ in the Medium Editor but nothing worked.

I will try again.

So you have a repeat that loops through all the records but inside it you use some conditions in the value expression that show certain records from all the records in the repeat?
You cannot use a repeat with these expressions as a medium editor value …
The question here is - why do you “filter” your data like that, and not filter the repeat/query for this?

It makes more sense to have:

repeat=" ...query.where(filters here)
{{value}}
/repeat

instead of

repeat=" ...query(all records returned by the query)
{{value.where(filters here)}}
/repeat

Your comments makes sense as always. Let me rework this and see if I can get it to work. :slight_smile:

I am sure this is possible and can get results with a simple ‘where’ clause but I am struggling with my particular ‘filtering’.

I am trying to turn a ternary operation, with 3 distinct conditions separated by '&&'s, into a where clause. Now I am struggling again.

Here is my initial ternary operation

(((commpara_state == sc_menus.data.q_menus.where('menu_list_id', inp_driv_rep_status.value, '==')[0].list_ref) && (((commpara_cond == inp_driv_rep_status.value) || (commpara_cond == veh_cond.value) || (commpara_cond == veh_taxi.value) || (commpara_cond == impact_temp.value)) && (commpara_cond_yesno == 1 || commpara_cond_yesno == 0))) ? (commpara_id + ' ' + commpara_text.stripTags()) : '' )

Hi @Teodor, I have managed to get this to work with one where condition, BUT I need to apply 3 conditions. Can I nest where clauses? Or can I daisy-chain where clauses?

Hey there Neil…

Yes, I daisy chain where clauses… I’ve not found a way to do it with the menu system but it works as an “and” function if you just put

.where(condition1).where(condition2).where(condition3)

and it will return the array items where condition1 and condition2 and condition3 are all true…

Good luck!
Antony.

2 Likes