geojoomla
Total posts: 73
27 Фев 2016 15:38

This is related to a previous post of mine.

When author saves the record, I need the output (text or html) to be the result of a combination of fields values.
Is it possible?
If so, until field concatenation (and conditioning) is doable via admin interface, I would appreciate a quick example of how I can echo (and condition, if possible) a combination of fields values on an output field template.

Thank you very much indeed.

*edit
I think output field template doesn't know about the value of another field - so I assume it's the final record template that needs to be worked on.

Последние изменения: 09 Март 2016


danielbidala VIP
Total posts: 153
28 Фев 2016 07:58

I don't understand what exactly you want. Do you want to combine two fields value into one field (store them in the db as one filed)? Or you just want to display two fields together in record template?


geojoomla
Total posts: 73
28 Фев 2016 09:42

Both would be ideal. I'll explain why.

  1. Combine multiple fields in record template.
    This I think is doable, after reading this
    I'm not 100% sure how to concatenate them (without hard-encoding fieldID, in desired order and without line breaks - to be interpreted/executed correctly - but am working on it.
    Any help for an average php/joomla user like me :) is much appreciated.
    With hidden fields and author's inputs I can make authors use whatever Joomla plugins I want.

  2. Combine fields into another field.
    This would be ideal because:
    2a. I would get the same effect using only one "final" field and not affecting the record template
    [shouldn't it also be more efficient/light on server? - no idea, just asking]
    and furthermore
    2b. Any "final" fields (resulted from combined fields) can be used for other purposes in different type/section, or even with other components) etc.

I suspect 2 is not that easy...


danielbidala VIP
Total posts: 153
28 Фев 2016 10:08

Which kind of fields do you want to combine? HTML and/or textarea?


geojoomla
Total posts: 73
28 Фев 2016 11:53

I would start with the simplest (from author's point of view), if possible:
- text
- single select (admin gives them the option to choose)

Then, as you suggest
- textarea
- html
But these last two - in my view, if ever possible - would work better with other admin actions allowed on them (trim, find/replace, regex etc).

In other words, let the author dump his stuff, admin uses the data, manipulates and puts it as intended.
That's how I see it done ideally :)

Thank you in advance, for any effort into this direction!


danielbidala VIP
Total posts: 153
28 Фев 2016 13:43

Just to be clear: You have two field. You want combine those into one and than store it in db as a separated field. I can only imagine that with predefined way:

You have the two field. You create one more and set Who can submit and Who can edit to no one. You must create a Cobalt plugin and create function with onBeforeArticleSaved event. In this function you can handle the fields and give your third field the value what you want. This function will be triggered before article save process has done. You can control which type or section must use this plugin. More info: COBALT EVENTS

Also you can handle this problem with jQuery but maybe the php way is more elegant.


geojoomla
Total posts: 73
28 Фев 2016 15:11

I understand the theory, thank you, but too complicated for me.
I was hoping for something simpler.
Before I "create a Cobalt plugin and create function with onBeforeArticleSaved event" I will focus on echo-ing fields into article (list) templates.
For now, it should be much easier to echo the hard-coded fields ($item->fields_by_id) and get rid of the original logic in the template.

Until Cobalt makes something similar to seblod or even better, I will have to pull my hairs with the templates, I might start to like them :)

Thanks


Sergey
Total posts: 13,748
03 Март 2016 02:17

Combination of fields is not possible and not practical. What if you want to edit article again? How do you separeate? FOr example textarea have "q w e" and html have "r t y". Combination would be "q w у r t y". When it is all one text how do you know what is part from textarea?

But you may get it look like it is combined by creating a cuustom template as suggested.


geojoomla
Total posts: 73
03 Март 2016 09:30

Understood Sergey, but the final field is neiher published, nor editable. You don't need to modify the "big field" (in your example "qwerty").
User/author is allowed to modify only the separate "bits", first "qwe", then "rty" - in this way he changes the big field.

The resulted fields are hidden, not to be changed themselves, but they "go live" on webpage as a unit, rendered by html/php as admin wants.


Sergey
Total posts: 13,748
08 Март 2016 05:29

geojoomla User/author is allowed to modify only the separate "bits", first "qwe", then "rty" - in this way he changes the big field.

I understand. But this is your case scenario. This is how you need it. You do not need it to be modifies. But when I add feature I have to think about all cases possible. If I add somethink like this, most of the people will complain that this is not editable, you should introduce half working features and so one.


Jeff VIP
Total posts: 745
09 Март 2016 09:45

geojoomla Combine multiple fields in record template.

echo strip_tags($item->fields_by_id[1]->result).strip_tags($item->fields_by_id[2]->result);

This concatenates the raw values of field_1 and field_2. Just make sure you haven't unset these fields earlier in your template.

Работает на Cobalt