Controlling number of times partial view is rendered

Hi there,

In my forms, I’m using my own field (standard form field with additional button next to it). This fields opens up a CJuiDialog (after clicking that button). Currently I’m generating partial view (that contains CJuiDialog declaration, contents and necessary JS code) in a view, where I use that field. I call renderPartial before calling function to draw field.

I would like to change it to have call for drawing field also handle rendering necessary sub-view.

Question, is this a good idea? And, how to control, if there are not more than one dialog rendered (i.e. if two fields of the same kind in the same form, all should use the same, one dialog). Is there any way to have some kind of "stack" of sub-views, "register" them for rendering (just as we do with scripts) and render all of them at once, controlling that, if any particular view is put into that "stack" twice or more, to render it once (exactly as with scripts)?

Do we have any tools in framework for such functionally? If not – would that be much work to do it myself? And is it worth doing so?

I figured out that a possible solution would be to rewrite sub-view to be 100% JavaScript (render dialog and it’s contents using pure jQuery UI functionality, as Yii would not exits) and register this script as the only Yii function in that sub-view. This way I could assure that particular dialog will truly be rendered only once, as particular JavaScript code would be registered once, even though there might be more than one call to that sub-view.

What do you think?