Only specific items disabled

@david.wylie,
I know it’s a post from long ago but still valid with the problem that I have. Could you kindly help me out on this same issue but targeting only a special TextBox or Fileloader in the form? I want only specific items disabled.

Here is the thing:
A. for TextBox
target texbox (per se): self.userid
target textbox (if inside a column panel): self.column_panel_compulsory.text_box_userid

B. Fileloader:
target: self.file_loader_validid
target fileloader inside col panel: self.column_panel_compulsory.file_loader_validid

The targeted components are built in one module that is imported in the form where I want it disabled.

Following your solution to this type pf problem, I duplicated your relevant codes but it doesn’t work for me. Here’s what I did.

I tested 2 functions then called it down the line where it fits:

## testing the function with TextBox inside the column panel container:

def disable_item(self):
     for c in self.column_panel_compulsory.get_components():
          if type(c) ==TextBox and c ==self.column_panel_compulsory.self.text_box_userid:
               c.enabled = False

## testing the function with TextBox without the containing column panel:

def disable_item(self):
    for c in self.get_components():
         if type(c) == Textbox and c == self.text_box_userid:
              c.enabled = False

## calling the function down the line
self.disable_item()

When I do a ’ print (c)’ in the console, I don’t get anything indicating that the code ‘if type(c)’ isn’t being recognized…no error generated in the console.

Would appreciate your help on this.

Thank you.

Admin note @koollucian.2012. Moved to a new topic. We usually dont revive old solved topics. Just simply link to the old one you want to reference.

Sorry. Thank you very much.

1 Like

Could you share a clone link? I suspect tbe reason you’re not seeing it is because the components you want disabled are in some kind of container and you have to use get component again on that container. I’m not 100% on this hence the clone link to check myself if what I’ve said is unclear.

Thank you @duncan_richards12 for your kind reply.

I wish I had thought of getting this problem resolved much earlier because at this time, the app is already hosted and probably way past the clone-linking stage. Stiil, I will carefully llok at your supposition that the problem maybe bedause it is be contained deeper in the app.

I wlll give an update after further testing.

If the code for this specific problem isn’t too big you can just make a minimal use case demonstrating all and share that clone link (like just the 2 forms in question)

OK, let me take a crack at reducing the relevant parts to share here. I am also testing the codes of @david.wylie in a test app. Will update here later.

1 Like

Hello @duncan_richards12,

I am sharing the clone link of a similar app to test the code on disabling-enabling Anvil compoments by @david.wylie. This app is actually the prototype of a bigger app that is hosted. While small, the prevaiilng issue can be teated.

Here is the clone link: Anvil | Login

I tested the codes on a button but it still could not make it work…asking for missing ‘self’ when I run the function. to see if the button is disabled.

Here are the codes that I used:

def disable_item(self, **event_args):
    for c in self.get_components():
      if type(c) == Button and c ==self.content_panel.add_member_button:
        c.enabled = False
  
  self.disable_item()

Would appreciate if you could help me make it work.

the tl;Dr of what the issue was that you needed to keep going down through all the components.

There were several things wrong with the clone:

  1. the add_member_button button component belongs to self not self.content_panel (so if you want to disable this button just do self.add_member_button.enabled = False)
  2. the self error was because it wasn’t under the form class
  3. The buttons I think you were looking to disable were waaaay down in the article view, so I had to do a lot of looping down into the nested articles_panel.

Here’s a clone link where I have looped all the way down from self to disable those buttons and then another version where I loop down just from self.articles_panel.

I’m not really sure about the workflow that leads to these components being disabled/enabled, but its probably better to do this within the ArticleView form, but I am not sure what the workflow is so that’s harder for me to help with without more details.

Thanks for looking at the problem.

Basically, this simple app is just an output from following the News Article tutorial app of Anvil, so the component layout pretty much followed it.

The “add_member_button” component does belong to the content_panel. I actually tested both (inside the content panel and outside as in “self.add_member_button.enabled = False”. Both ways did not disable the button…

Incidentally, the add_member_button is at the top of the content_panel in the HomePage. It can only be modified there, not in the ArticleView.

Thanks for the inputs, just the same.

Just a quick update here.

I tested a simple app in Anvil to check the enable method in a very simple setting,…test button inside a content_panel (ColumnPanel). The method works so my problem is likely due to my target components lying a bit down the component hierarchy. It is not a problem with the method.

I would say that this topic is solved…all I need to do is clear up the workflow.

Thank you @duncan_richards12 for the lead.

1 Like

Sorry I was away for a few days and missed your messages - glad you found a solution.

Thank you for catching up.

I just thought to declare it as resolved … as far as finding the root cause is concerned. I haven’t yet cleared it myself. One thing I could see, if the component is not inside the content panel, I could not disable it and that’s likely why I could not do it in my app. I checked this out in a simple test app.

Given that, do you think there may be another way, short of totally revamping my form? Would putting that target form (where the target component to be disabled reside) inside the calling form work? What about declaring that component globally so it is available in every form (something I would favor if that component is common). Sorry, these are wild thoughts perhaps.

Would appreciate your thoughts on this.