Multiple instances of custom widget


Hi All,

I'm writing a custom widget that will be instantiated multiple times in a form.

How can I reference this specific instance elements in the controller function?

I tried generating random id´s, but it seems the template is not ready when the controller function is executed, so $("#" + randomId) generates a JavaScript exception.

Thank you.

1 answer

This one is the BEST answer!


What are you trying to achieve? Normally the controller will have access only to the data manipulated by its template. So even though, we put multiple times the same widget on the a single page, the behavior of the widget should be affected.

By example, here you can find the source code of a fileUpload widget. You can did a test where you declare multiple times the fileUpload widget on a page, you will see that each widget manage its own file.



Submitted by edo_2 on Thu, 07/20/2017 - 22:20


Thank you for your answer.

In fact, we were building the customAutoCompleteInput, which we found in the repository. Duh!

Best regards.