• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

SDK Dialog Ok button only enabled if edit_field is not empty

Explorer ,
Jan 20, 2023 Jan 20, 2023

Copy link to clipboard

Copied

What I want is to have the dialog Ok button only be enabled when a edit_field is not empty.

 

In the post https://community.adobe.com/t5/lightroom-classic-discussions/modale-validation/m-p/9351740 John Ellis gives the following example which I extended by one edit_field.

Setting the check on the popup_menu works, setting it on the popup_menu works not.

 

2 questions:

  1. What am I missing that this doesn't work for the edit_field
  2. What is the most easy way to disable the Ok button if an edit_field is empty.

If possible I want to stay away from using addObserver

 

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"}}
				},
				f:edit_field {
					alignment = 'left',
					place_horizontal = 0,
					value = bind( 'taskDescription' ),
					width_in_chars = 20,
				},			
			},

--			actionBinding = {enabled = LrBinding.keyIsNotNil ("selection", p)}}
			actionBinding = {enabled = LrBinding.keyIsNotNil "taskDescription", p)}}


	end)

.

TOPICS
Cross-app workflows , SDK

Views

93

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , Jan 21, 2023 Jan 21, 2023

Awesome John

I works, you nailed it again!

Likes

Translate

Translate
LEGEND ,
Jan 20, 2023 Jan 20, 2023

Copy link to clipboard

Copied

I'm probably in a minority, but I actually really like Lua as a scripting language. But your issue illustrates why many hate it.  A number of issues, which took a bit to resolve:

 

- There was a syntax error, probably a copy/paste problem:

actionBinding = {enabled = LrBinding.keyIsNotNil "taskDescription", p)

should have been:

actionBinding = {enabled = LrBinding.keyIsNot ("taskDescription", "", p)

 

- The edit_field() needs the "immediate = true" property.  Otherwise, its bound value won't get updated until the keyboard focus leaves the edit field.

 

- The value of p.taskDescription defaults to nil, but as soon as the user edits it and then erases the content of the field, its value changes to the empty string.  So the solution is to initialize p.taskDescription to "" and then use:

      actionBinding = {enabled = LrBinding.keyIsNot ("taskDescription", "", p)}}

 

So a working script is:

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)
    p.taskDescription = ""
    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"}}},
            f:edit_field {alignment = 'left', place_horizontal = 0,
                width_in_chars = 20, immediate = true, 
                value = bind "taskDescription"},  
            f:static_text {title = bind "taskDescription"}},
      actionBinding = {enabled = LrBinding.keyIsNot ("taskDescription", "", p)}}
    end)

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 21, 2023 Jan 21, 2023

Copy link to clipboard

Copied

LATEST

Awesome John

I works, you nailed it again!

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines