Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

child template redirecting to parent #410

Closed
eatyourpeas opened this issue May 22, 2022 · 2 comments
Closed

child template redirecting to parent #410

eatyourpeas opened this issue May 22, 2022 · 2 comments

Comments

@eatyourpeas
Copy link

Almost certainly my bad tbh but my child component seems to be triggering events in the parent component, not in its own UnicornView. It could be because I have nested one component in another, so the parent is itself a component called from a Django template and that is sending it up its arse. If you can shed any light, or if this is a vulnerability to highlight, I am grateful to know either way.

Parent component: components/is_epilepsy.py

class IsEpilepsyView(UnicornView):
    desscribe = DESSCRIBE.objects.none()
    case_id = ""
    registration = ""

    def __init__(self, *args, **kwargs):
        super().__init__(**kwargs)  # calling super is required
        self.case_id = kwargs.get("case_id")
        self.registration = kwargs.get("registration")

...

Parent template: templates/unicorn/is_epilepsy.html

...
 <div class="ui blue segment">

        <div class="ui header">
            <div class="ui blue circular label">S</div>
        </div>

        {% if selected_epilepsy_status == "E" %}
            {% load unicorn %}
            {% unicorn_scripts %}
            {% unicorn 'epileptic_seizure_onset' parent=view %}

        {% elif selected_epilepsy_status == "NE" %}
            
            {% load unicorn %}
            {% unicorn_scripts %}
            {% unicorn 'nonepileptic_seizure_onset' parent=view %}

        {% else %}
            <div class="ui message">
                Uncertain
            </div>
        {% endif %}
    </div>

The parent component contains a select element which should render different children depending on the value selected.

Each child (epileptic_seizure_onset and non_epileptic_seizure_onset) has a corresponding UnicornView component which mounts. However, any change etc events within these children fire not in their own component logic (found in components/epileptic_seizure_onset and components/non_epileptic_seizure_onset.py), but in the parent (is_epilepsy.py). In the console, the url I see is:

[22/May/2022 20:19:27] "POST /unicorn/message/is_epilepsy HTTP/1.1" 200 4639
[22/May/2022 20:19:40] "POST /unicorn/message/is_epilepsy HTTP/1.1" 200 2867

I am guessing this is my implementation rather than an issue as such?

@Matthijz98
Copy link

I have the same issue.
The function in a child components are send to the parent component.
For now i just made it one big component but child components would make it a lot less cluttered

@adamghill
Copy link
Owner

I think this should be fixed by 0.58.0 of Unicorn which drastically improves child components so I'm going to close it. If it is still a problem feel free to re-open this and create a failing test or small example in the example app of this repo to replicate, though. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants