×
We value your feedback! Please click here to access our 2024 Client Survey.
The survey will remain open until November 1st. Your perspective will help guide our product/service planning and goals for the upcoming year and beyond!

Simple Module HTML elements id`s

LabKey Support Forum
Simple Module HTML elements id`s kune  2014-10-31 02:37
Status: Closed
 
Hello,

I tried to construct a simple module consisting of HTML, some javascript files, image files and css files and defined webpart xml. Everything worked as i expected until i tried to add the same module webpart twice on the same page... These identical modules mixed their layouts together. I expect it`s because of clashing IDs of HTML elements. Is there a way to provide private a namespace of module or should i walk around it using HTML classes instead of IDs?

Thank you for your response, Michal
 
 
Ben Bimber responded:  2014-10-31 08:12
Hi Michal,

We typically do something like:

<script type="text/javascript">

Ext4.onReady(function(){
    //this is a substitution that will write an object with context about your page, including the ID of the DIV created for this webpart.
    var webpart = <%=webpartContext%>;

    //this element will be specific to this instance of the webpart, so it will be safe if there are multiple on the same page.
    Ext4.get(webpart.wrapperDivId).update('Hello World');
});

</script>

That is similar to the <%=contextPath%> and <%=containerPath%> substitutions you might be familiar with. If you have checked out a local copy of labkey from svn, you might look at the modules under \externalModules\labModules or \externalModules\DISCVR for some of our examples.
 
kune responded:  2014-11-03 02:05
Thank you Ben,

i`ll try it asap...

Michal