Hi,
I have a binding problem in my LrPluginInfoProvider.sectionsForBottomOfDialog function, and i cannot make it work; i've read all the docs, view all the samples, but i just can´t see where the problem is ...
I have this code in my Info.lua
return {
...
LrPluginInfoProvider = 'PluginInfoProvider.lua',
...
}
PluginInfoProvider.lua has this code:
require 'PluginManager'
return {
sectionsForBottomOfDialog = PluginManager.sectionsForBottomOfDialog,
}
And this is PluginManager.lua:
local LrView = import 'LrView'
local LrDialogs = import 'LrDialogs'
local LrLogger = import 'LrLogger'
local myLogger = LrLogger('logger')
myLogger:enable("logfile")
PluginManager = {}
function PluginManager.sectionsForBottomOfDialog(viewFactory, propertyTable)
propertyTable.text = ""
propertyTable.buttonEnabled = false
return {
{
title = "Test",
viewFactory:row {
spacing = viewFactory:control_spacing(),
viewFactory:static_text {
title = LOC "Text",
},
viewFactory:edit_field {
value = LrView.bind "text",
validate = function( view, value )
if #value > 0 then -- check length of entered text
propertyTable.buttonEnabled = true
else
propertyTable.buttonEnabled = false
end
return true, value
end,
},
viewFactory:push_button {
enabled = LrView.bind 'buttonEnabled',
action = function(button)
myLogger:trace("Test value")
myLogger:trace(propertyTable.text)
end,
},
}
},
}
end
As far as i know, the button should enable only when there is some info in the text field and log file should show the text field value, but it only displays "Test value" and the button is always enabled.
Any idea? i'm really
with this ... (i don't know if matters, but i'm testing this in a WinXP machine with LR 2.3)
Thanks in advance,
It looks like you need to tell the controls which property table to bind to.
In this code, try adding "bind_to_object = propertyTable," to the row.
To make the button enable as soon as there is more than 0 chars in the textbox, add "immediate = true," to the edit_field. This will run the validate function as the user types.
Thanks Mark,
I knew about inmediate property, just forgot tu un-comment it ![]()
I've added "bind_to_object = propertyTable" as you say, but it didn't work; i've renamed the parameter propertyTable to propTable and now it does ... and i've no idea why ![]()
Anyway, it's working ok, so thanks for your answer.
As you have figured out, the value of the edit_field will not change until it is validated and it will only be validated with every keystroke when "immediate = true".
Another way to accomplish this would be to bind the enabled state of the button to the value of the edit field. Such as:
enabled = LrView.bind {
key = "text",
transform = function( value, fromTable )
if fromTable then
if value ~= nil and value ~= "" then
return true
end
return false
end
end
}
(This was not tested but should be close)
The advantage of this is that the button will be enabled and disabled without the validation of the edit_field needing to be called. So if the value of the text field is changed programatically the button will be updated.
North America
Europe, Middle East and Africa
Asia Pacific