objecthub-io / ObjectHub

ObjectHub is an open repository for software objects and a development platform.
2 stars 1 forks source link

'elem' parameter not isolation app elements #281

Closed michaelbukachi closed 7 years ago

michaelbukachi commented 7 years ago

So I'm trying to set the ID of an element inside an embedded app. But it seems not to isolate the element. For some strange reason, every element with the matching selector receives the same ID. I did a test with the following snippets and was able to replicate the bug. Here's the code for the main app:

<div data-embed='Embedded' data-id='1'></div>
<div data-embed='Embedded' data-id='2'></div>

Here's the code for the embedded app:

<div class="embedded">
    <p>
        Some random text
    </p>
</div>

And the javascript:

app.init = function(cb) {
    // add logic to initialize UI here.
    $('.embedded', elem).attr('id', 'embedded'+params.id);
    cb();
};

Here's the result I get when I preview the app screenshot from 2017-08-10 20-53-12

From the screenshot you can see that those two embedded apps are sharing the same id.

objecthub-io commented 7 years ago

Thank you for this questions.

The problem is that you embed the same app twice with the same name data-embed='Embedded'.

Open the dependencies and rename the variable for the import to Embedded1. Rename the variable in the HTML. Delete the second embed. Drag and drop the Micro App to be embedded on the form again. Give the variable name Embedded2.

We added that the preview will show an error if the same variable name is used twice for a Micro App and updated the documentation.

michaelbukachi commented 7 years ago

Okay. Got it. Thanks