It is possible to pass custom js to a widget, as explained in the documentation. In my case, the custom js is this:
function setUpImagePreview(inputId, imgId) {
...
}
window.onload = function() {
// IDs hardcoded, VERY BAD! How to solve this?
setUpImagePreview('id_brand_logo', id_brand_logo_img');
};
I am using this to control some effects on a forms.FileField
. The important thing here is that the IDs are related to the specific field that I am rendering. There will be possibly more than one such field in a form, so I need to be able to:
- pass the element IDs (
id_brand_logo
andid_brand_logo_img
) to the script - run the script for each Widget, not just once for the whole page
Is this possible to achieve with django Widgets / Forms?