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

updating child components via a parent method #666

Open
jacksund opened this issue Feb 26, 2024 · 1 comment
Open

updating child components via a parent method #666

jacksund opened this issue Feb 26, 2024 · 1 comment

Comments

@jacksund
Copy link
Contributor

jacksund commented Feb 26, 2024

Branching from #662

I have a question about going one step beyond your example in the docs -- Can force_render be applied to a list of children components? I'm struggling to get this to work as expected. For example say I add the following method & html to the table component:

# method added to TableView

def begin_edit_all(self):
    for child in self.children:
        if hasattr(child, "is_editing"):
            print("child set to editting")
            child.is_editing = True
            # child.force_render = True  # doesn't trigger refresh
    # self.force_render = True # doesn't trigger refresh
<button unicorn:click="begin_edit_all"
        type="button">
    Edit All
</button>

My attempts to force_render child components fail. And as a more complex example, using filter + begin_edit_all applies to all books rather than those that have been filtered:

image

Here are the files for this example:
mysite_example3.zip

A more realistic example of this would involve a table where you want to apply a status to all child components. For example, we could have a list of tasks that are filtered down and then you apply a set_status_complete to these filters items - that updates the table + status column.

@alexandry-augustin
Copy link

Hi,

I can confirm that I am also witnessing the behaviour you've described.

I would also highlight an even simpler case taken from the example in the documentation. It seems that setting the value of children from the parent doesn't produce the desired effect:

    def load_table(self):
        self.books = Book.objects.all()

        for child in self.children:
            if hasattr(child, "is_editing"):
                child.is_editing = True # This is not having any effect whatsoever

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

2 participants