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

Modale validation

Community Beginner ,
Sep 12, 2017 Sep 12, 2017

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

TOPICS
SDK

Views

339

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

LEGEND , Sep 12, 2017 Sep 12, 2017

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.

Votes

Translate

Translate
LEGEND ,
Sep 12, 2017 Sep 12, 2017

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.

Votes

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
Community Beginner ,
Sep 13, 2017 Sep 13, 2017

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.

Votes

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
Community Beginner ,
Sep 13, 2017 Sep 13, 2017

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?

Votes

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
LEGEND ,
Sep 13, 2017 Sep 13, 2017

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.

Votes

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
Community Beginner ,
Sep 14, 2017 Sep 14, 2017

Copy link to clipboard

Copied

LATEST

Thank you John!
Thhat's working perfectly!!

All the best

Votes

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