design direction needed: drop down in widget extension

Hi all,

I need a little design suggestion:

I implemented a widget extension that holds a flash element.

Now I need to have a little drop down that upon selection, will update the flash containing DIV to load a different flash from the server.

Now, I’m not too familiar with Yii extensions or its core functionality that might help me here. Rendering a small drop down and the jQuery code to catch its change and ‘refresh’ the flash div isn’t a big deal to write.

Would you recommend me to use some ready-made tools/capability you’re aware of?

TIA,

Boaz.

You could inspect widget sources that implement a similar basic logic. CCaptcha comes to my mind here. It should give you an idea how you can organize your code. E.g. look at its registerClientScript() method, where the jQuery code is kept. It also splits up the job in 2 classes: the main widget class + an action class that renders the image.

Thanks Mike for the pointer. Its not exactly what I need to implement but similar and reinforce what I had in mind.

I think that my recipe will include a CHtml::dropDownList() where I would specify besides the drop down values also my JS code to run on a "change" of value (I need to see how to do it. Not a big deal for sure).

Then, the JS code itself will simply replace the needed div’s content with updated JS code that itself renders the flash chart. This is FusionWidget flash BTW. It starts by running their JS and that fetches the SWF and runs it.

Thanks,

Boaz.

Ok, here’s what I did thus far. All finished besides the flash part itself:

  • in the view file for my extension I’m using [font=“Courier New”]echo CHtml::dropDownList(‘specificId’…);[/font]

  • in the widget class run() method I did a [font="Courier New"]Yii::app()->getClientScript()->registerScriptFile(<my assets published script path>);[/font]

  • The mentioned JS script file contains something along:




$(document).ready(function() { 

	$('#specificId').change(function() {

		// here comes the important JS code, yet to be written... 

        });

});



Did you use the widget view for this? If not, i think it would make sense to do so. The widget could render the dropdown + initial flash div + jquery. You can add properties to configure formatting and the like.

Yep, a widget view is in place and used by this widget. The code snippet (CHtml::dropDownList) is used within that view. Prepared values are digested by the widget class and passed to this view. All done “by the book” :slight_smile: (hopefully. i’m new to Yii)