This object is in archive! 

Widget Default Category

Archived Graham Mayers 10 years ago

Is there a way to pass a default category to the widget?


I would like to embed the widget on many of our internal sites and it would be preferable to pre-select the category that the specific embedded widget pertains to so that we obtain accurate feedback based on the site the widget is embedded in, removing the category choice from the user.


When a user submits feedback from the main UR site, category selection would still be available.

Best Answer
photo

Sorry there is no such built-in functionality. You can do it only on custom basis with js

Replies (6)

photo
1

Sorry there is no such built-in functionality. You can do it only on custom basis with js

photo
1

So I have made quite a bit of progress on this one. I am able to select the category based on supplying a parameter in the URL, but I can't seem to figure out how the hidden form elements for the categoryID is appended to the widget.


I assume something is firing an onChange event on the category select element, but I can't find it. Could you help?

photo
1

Graham,

The most correct way is to add the proper hidden element to the Response form using event handle.

You may find this code area inside /application/modules/categories/handlers/Events.php file.

Find public static function onFormInitAfter ($form) method, then find the following code where "Categories" module is adding own fields to the response form:

  1. if ($form instanceof System_Form_Response) {
  2. $categoriesDb = Singular_Loader::get('Categories_Model_DbTable_Categories');

By parity of reasoning add your hidden element for the default category.

After this action you can handle hidden element value in public static function onAfterSave ($object) to store it into database.

photo
1

Thanks Paul - a bit over my head, but I'll give it a go!


I'll update with progress...

photo
1

So, I don't think I articulated what my goal was very clearly, but I think what Paul was referring to was slightly different.


I ended up doing the following:

  • Changed URL of embedded widget to include a categoryName parameter - you have to manually add this, but it works for my needs.
  • In global.js, I check for existence of categoryName in the URL and then insert the relevant hidden input fields and hide the ability to change/add categories.

photo
1

Graham,


Now I understand what are you talking about.

You need to write your own implementaion. It's too hard to help you here to make headaway.

Try to pass the category_id to the widget iframe via get param, i.e: ?cid=8

Replies have been locked on this page!