errorsDict

Posted on
Fri May 15, 2020 1:56 pm
howartp offline
Posts: 4136
Joined: Jan 09, 2014
Location: West Yorkshire, UK

errorsDict

I'm using validateDeviceConfigUi() but not finding any reference on the docs or forums as to how to use errorsDict other than several mentions of "...and this can return an errorsDict".

As an end-user I see the red warning "Error validating fields. Hover over the red field labels" but how to I program those red labels or other such error handling when I return the failed validation?

Posted on
Fri May 15, 2020 2:14 pm
DaveL17 offline
User avatar
Posts: 5529
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: errorsDict

Here's a small sample from the Matplotlib plugin.

Code: Select all
        error_msg_dict = indigo.Dict()

        try:
            if float(values_dict['lineWeight']) <= 0:
                error_msg_dict['lineWeight'] = u"The line weight value must be greater than zero."
        except ValueError:
            error_msg_dict['lineWeight'] = u"The line weight value must be a real number."

        if len(error_msg_dict) > 0:
            return False, values_dict, error_msg_dict

You can also add a pop-up window:
Code: Select all
    error_msg_dict[“showAlertText”] = “Some very descriptive message to your user that will help them solve the validation problem.”

Note: I'm crazy swamped IRL and it may be a while before I can respond to messages or bug reports. Thanks for your patience.
-----
I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Fri May 15, 2020 2:42 pm
howartp offline
Posts: 4136
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: errorsDict

Ah, that popup window is very useful!

I've been digging through other plugins since I posted and i'd just about come up with a working errorsDict but that's a nice addition.

Posted on
Fri May 15, 2020 2:59 pm
DaveL17 offline
User avatar
Posts: 5529
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: errorsDict

As another hint, you can flag multiple items in the same return.

Code: Select all
       error_msg_dict = indigo.Dict()

       error_msg_dict['thing1'] = u"The line weight value must be greater than zero."
       error_msg_dict['thing2'] = u"Some other message of import."
       error_msg_dict[“showAlertText”] = “Some very descriptive message to your user that will help them solve the validation problem.”

       if len(error_msg_dict) > 0:
           return False, values_dict, error_msg_dict

Note: I'm crazy swamped IRL and it may be a while before I can respond to messages or bug reports. Thanks for your patience.
-----
I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest