Update Custom Field Based on Category

More
10 years 4 months ago #42702 by nlssteve
Hello,

I have Custom Fields in my Items that have values driven from the Categories which have been selected for the Item.

Example:

(Category Setup):
Age Levels (category_id=11)
- Novice (category_id=12, parent_category=11)
- Atom (category_id=13, parent_category=11)
- Peewee (category_id=14, parent_category=11)

Custom Field:
fAgeCategory
Field Values:
All categories where parent_category=11

I would like to update the custom field (fAgeCategory) with the Categories that have been selected for the Item automatically and keep them up to date every time the category is changed.

I believe that I could create a new Field Type (plugin) that is a copy of the checkbox type and add custom code to the onBeforeSaveField function.

For each Category assigned to the Item
If the parent category = 11 then
update the fAgeCategory field

I just don't know how to write the code to do this. Any help would be appreciated.

Thanks.

Please Log in or Create an account to join the conversation.

More
10 years 4 months ago #42732 by ggppdk
Hello

what about using a FLEXIcontent field of type select / selectmultiple / checkbox / radio

and set it's elements to be created via an SQL query

or are you doing this already ?


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star...

Please Log in or Create an account to join the conversation.

More
10 years 4 months ago #42746 by nlssteve
Thank you for your reply.

I am already using the checkbox field for this where I have a query to create the values.

Problem 1:
The values are not "checked", so I had to modify the checkbox.php file to remove the following lines in order to have the values show up normally in the Frontend:
Code:
$ns_pretext = $ns_pretext . '<span class="fc_field_unsused_val">'; $ns_posttext = '</span>' . $ns_posttext;

Problem 2:
I can't figure out how to get both the value and the text for each item returned by the query. I use the {{fAgeCategory##0##_text_}} replacement value, however it only returns the values at index 0. How can I get it to return all values in the array?

Please Log in or Create an account to join the conversation.

More
10 years 4 months ago #42747 by ggppdk
Hello

1. you can do this via parameter,
so this change is unnecessary,
please restore the field so that you can upgrade later without problems

-- these lines are used only if you enable the display of ALL values (including the unused ones), so go to your field configuration and disable showing of unused values
and even if you enable this setting and display is not as expected (see popup description in parameters) then you should check CSS that may alter the display of them


2. {{fAgeCategory##0##_text_}}
will not return the values it will return the label , it may return the value if you have a custom SQL
to get both value and label you may try:
{{fAgeCategory##0##_text_}}
{{fAgeCategory##0##_value_}}

-- if you need functionality not available, then you may consider creating a custom field:
How to Duplicate a Flexicontent Field to create a new Field Type
API methods of FLEXIcontent fields

Regards


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star...

Please Log in or Create an account to join the conversation.

Moderators: vistamediajoomlacornerggppdk
Time to create page: 0.305 seconds
Save
Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Essential
These cookies are needed to make the website work correctly. You can not disable them.
Display
Accept
Analytics
Tools used to analyze the data to measure the effectiveness of a website and to understand how it works.
Google Analytics
Accept
Decline