* Forcing an Iup text field to have a value

For users to report plugin bugs and request plugin enhancements; and for authors to test new/new versions of plugins, and to discuss plugin development (in the Programming Technicalities sub-forum). If you want advice on choosing or using a plugin, please ask in General Usage or an appropriate sub-forum.
Post Reply
User avatar
ColeValleyGirl
Megastar
Posts: 5465
Joined: 28 Dec 2005 22:02
Family Historian: V7
Location: Cirencester, Gloucestershire
Contact:

Forcing an Iup text field to have a value

Post by ColeValleyGirl »

I have some text fields in a plugin that must not be left blank. There are toggles the user can set to disregard a field (rather than use a blank value).

I can set a mask of "/S+" to ensure that, if the user does enter anything, it must be at least one non-blank word character, and initialise to a non-blank default value.

But If the user deletes everything and moves on, the mask doesn't kick in.

MASKNOEMPTY isn't available in the version of Iup we use.

I can do something with the killfocus_cb callback (like replacing the default) but I'd prefer a different solution that prevents the situation arising because modifying user data isn't a good idea (especially when they don't notice it's happened for example when they clear the field and immediately press a button that closes a form.).

Any ideas?
User avatar
tatewise
Megastar
Posts: 28341
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Forcing an Iup text field to have a value

Post by tatewise »

Sounds like you are using the predefined dialogue IupGetParam rather than your own designed dialogue?
With the latter there is the text field action callback that lets any editing be reviewed before accepting the change.

IupGetParam also has a general action callback (2nd parameter) in which you can test which field, button, etc, is being changed and its value, and reject it by returning 0.

Code: Select all

function paramAction(iupDialog,intIndex)
   local iupField = iup.GetParamParam(iupDialog,intIndex)
   local strField = iupField.value
   if intIndex == 3 and strField == "" then return 0 end
etc...
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
ColeValleyGirl
Megastar
Posts: 5465
Joined: 28 Dec 2005 22:02
Family Historian: V7
Location: Cirencester, Gloucestershire
Contact:

Re: Forcing an Iup text field to have a value

Post by ColeValleyGirl »

No, I'm using my own dialog.

The Action callback is hard to use as it fires for every character change... and you never know which is the last!

valuechanged_cb doesn't allow you to reject the change.
User avatar
tatewise
Megastar
Posts: 28341
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Forcing an Iup text field to have a value

Post by tatewise »

When do you need to perform the validity check?
Is it when dialogue is closed, in which case use close_cb callback and return iup.IGNORE if text values not OK.
Is it when a button is pressed, in which case use the button action and return iup.IGNORE if text values not OK.
You could also popup an error message dialogue.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
ColeValleyGirl
Megastar
Posts: 5465
Joined: 28 Dec 2005 22:02
Family Historian: V7
Location: Cirencester, Gloucestershire
Contact:

Re: Forcing an Iup text field to have a value

Post by ColeValleyGirl »

I can use the close_cb callback, but that will involve changes to some boilerplate (with extensive retesting of 3 plugins.). Might be the only way though.

Hey ho.
User avatar
tatewise
Megastar
Posts: 28341
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Forcing an Iup text field to have a value

Post by tatewise »

What I do with my boilerplate libraries is allow the close_cb function to be optionally specified by caller.
So could you supply the function as an optional parameter, or supply the dialogue with the close_cb predefined?
Then existing usage without the optional extras does not need significant testing.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
ColeValleyGirl
Megastar
Posts: 5465
Joined: 28 Dec 2005 22:02
Family Historian: V7
Location: Cirencester, Gloucestershire
Contact:

Re: Forcing an Iup text field to have a value

Post by ColeValleyGirl »

I do much the same, passing parameters in a table.

Unfortunately, in this case the boiler plate is not for simple iup fields, it's for a whole sub-system of config management...

I shall work it out. At least I know I haven't overlooked a mechanism I could explore.
User avatar
tatewise
Megastar
Posts: 28341
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Forcing an Iup text field to have a value

Post by tatewise »

I've given this a bit more thought.
The text field rules are a bit catch 22.
An empty field is invalid (unless the disregard toggle is selected).
But the user is allowed to delete the field contents in order to enter a new value, so an empty field is valid.

Do you have a Close button that closes the dialogue and performs whatever needs to be done?
I use the .Active attribute quite extensively to enable/disable dialogue features such as that.
So in the text field ACTION or VALUECHANGED_CB callback, when the value is empty, set Close.Active = "NO" to inhibit the button and thus its ACTION callback is not invoked.

If there are several conditions that must be met, then you will need a single parsing function that checks all the conditions and is called by the ACTION callback of every associated field and toggle.
e.g. Field A can only be empty if its disregard toggle is set, and likewise for field B.
If any of the conditions fail then Close.Active = "NO" else Close.Active = "YES".

That Close button ACTION callback is very different from the dialogue CLOSE_CB callback, which should be treated as abort/cancel.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
ColeValleyGirl
Megastar
Posts: 5465
Joined: 28 Dec 2005 22:02
Family Historian: V7
Location: Cirencester, Gloucestershire
Contact:

Re: Forcing an Iup text field to have a value

Post by ColeValleyGirl »

I have two Close buttons: Confirm and Cancel (which resets the form to the values when it was invoked before exiting).

Re catch-22:

An empty field is invalid only when the Confirm button is pressed, otherwise it is assumed to be a point on a journey to a valid field.

I also use the .Active extensively, with a single function to check all conditions...

I shall explore valuechanged_cb

(Annoyed aside; I'd hoped to have the new version of this plugin ready for release on Monday after a weekend away but it ain't going to happen. At least my trip to the NLW is cancelled -- niece comprehensively broke her ankle and heel -- so I don't need to focus on that after I come back from the writing workshop I'm running this weekend).
Post Reply