Reopening a vb-view, how to do? + other


I setup a vbview and now would like to close it and the re-open it. I stumbled here over 2 problems:

  • dialogPtr:close() and thendialogPtr:show() does not work. Shouldn’t it at least reopen the thing? Is there a method for “regenerate” or similar?

  • If I want to rebuild it, it throws an error “‘custom_dialog: content view was already added to some other view or dialog.’”

Obviously I did not yet fully understand the logic behind this.

What I want is to regenerate / rebind the dialogue and then reopen it. I already tried to wrap it into a function and calling it recursively, but wasn’t successful.

The third question is, how to target a control itself within the notifier-function? Let say this code:

vb:textfield {
                    value = tostring(data[index]), 
                    width = 80, 
                    tooltip = val.txt, 
                    notifier = function(newValue)
                        if (tonumber(newValue) == nil) then
                  "Only use numeric values in the field "..index.."!")
                            data[index] = tonumber(newValue)
                            if (callbackRefresh ~= nil) then

On error, I also want to reset the value of that textfield. How can I address it in the most easy way? Am I forced to use an id then?

In Javascript afaik “this” always targets the most inner scope, so here this would be super easy (I even can do this.parent etc). In lua it seems that “self” only is available for classes / outer objects?

Yeah, the logic for opening/rebuilding dialogs can be a bit complex.
I’ve had good experiences with the approach used in vLib:

As for how to target a control itself, you just add an ‘id’ property to your element.
Then you can access it from anywhere in that viewbuilder instance, using this syntax:

 id = "my_button",
 notifier = function()
  local the_button = vb.views["my_button"] = false

But, be aware that once you absolutely need to destroy views with ids if you plan on (re-)building them - an id can be defined only once (it’s unique).

Sometimes, it’s preferable to just make a reference to your vb element, like this:

local my_button = nil

local my_button_handler = function() = false

my_button = vb:button{
 notifier = function()

Both are valid approaches, sometimes one fits better than the other.

Very helpful, thanks!