Copy link to clipboard
Copied
Hi All,
Is there a way to have a custom function when a user click on the ok button of a modal?
I'd like to validate that an edit-field is filled before exiting the modal and if the validation is not correct, show a new message in red inside the modal to show where is the problem (as the form on Internet)
Currently, I have an option by saving the elements and show a new modal if the validation doesn't pass, but I would prefer to do it by binding or something similar...
Thank you
Martin
You can enable or disable the action button of the dialog by setting the "actionBinding" parameter to a property binding:
local result = LrDialogs.presentModalDialog {title = "My Dialog",
contents = controls,
actionBinding = {enabled = {bind_to_object = prop,
key = "actionEnabled"}}}
You can use more complicated bindings created by LrBinding, e.g. to call a function that evaluates a more complicated condition.
Copy link to clipboard
Copied
You can enable or disable the action button of the dialog by setting the "actionBinding" parameter to a property binding:
local result = LrDialogs.presentModalDialog {title = "My Dialog",
contents = controls,
actionBinding = {enabled = {bind_to_object = prop,
key = "actionEnabled"}}}
You can use more complicated bindings created by LrBinding, e.g. to call a function that evaluates a more complicated condition.
Copy link to clipboard
Copied
Sounds a good solution to me š Thank
A bit less interactive than what I'd like to do but it's still good.
Thank you John.
Copy link to clipboard
Copied
I just made my tests.
It works with checkbox or so. But when I have a radio button, it does a strange stuff.
If I select an Item, it remove the result as soon as I click on it and I have to click again to get it.
local f = LrView.osFactory()
local p = LrBinding.makePropertyTable( context )
local res = LrDialogs.presentModalDialog {
title = title,
contents = f:row {
fill_horizontal = 1,
spacing = f:control_spacing(),
bind_to_object = p,
f:popup_menu {
fill_horizontal = 1,
items = items,
value = bind 'selection',
},
},
actionBinding = {enabled = {bind_to_object = p,key = "selection"}}
}
-> The button ok is then always active... Did I a mistake?
Copy link to clipboard
Copied
Here's a script that works as expected:
local LrBinding = import "LrBinding"
local LrDialogs = import "LrDialogs"
local LrFunctionContext = import "LrFunctionContext"
local LrView = import "LrView"
local bind = LrView.bind
LrFunctionContext.callWithContext ("test", function (context)
local f = LrView.osFactory ()
local p = LrBinding.makePropertyTable (context)
local res = LrDialogs.presentModalDialog {title = "Test",
contents = f:row {bind_to_object = p,
f:popup_menu {value = bind ("selection"),
items = {{title = "A", value = "A"}, {title = "B", value = "B"}}}},
actionBinding = {enabled = LrBinding.keyIsNotNil ("selection", p)}}
end)
The problem with your test was that actionBinding.enabled was expecting a binding that yielded the boolean values true or false. While in most places in Lua and the LR SDK, you can pass nil and non-nil values where booleans are expected, there are a few places that doesn't work, and this appears to be one of them.
Copy link to clipboard
Copied
Thank you John!
Thhat's working perfectly!!
All the best