A DropDown Placeholder Option

I’m trying to implement a DropDown that requires the operator to make a selection. If a selection is not made no callback occurs and querying the selection returns “invalid selection”.

One might describe this as a place-holder for the DropDown like this:
image

Currently I can only do this If the selection list actually contains “- select -” :
image

But I don’t want the operator to be able to choose “- select -” and I want to know if a selection has been made or not.

Has anyone come across this and has a solution or suggestions. As always you comments are appreciated.

Greg

A Bit More Background for Context:
Accepted, all the list choices are valid. So what’s the problem?

When the UI is initialised the default selection is Father but no callback is triggered resulting in the UI’s controller not capturing the default selection.

I can arrange to read the setting when UI Save button is pressed but is to late in the workflow. Consider:

Entering two people: Father and Mother, represents a reasonable paring as does Mother and Child, Father and Grand Parent. However: ‘Common-Law Partner’ and ‘Civil Partner’ would not (in the UK there is a legal distinction) as with Mother and Father. Actioning check at the save action makes it challenging to highlight the issue and resolving it. I’ve gone down this route and it a real brain teaser.

I would just keep what you currently have, and validate that the user has selected something other than the placeholders once they ‘commit’ the changes, however that is done, e.g. by trying to press a “Next” button. You could perhaps even keep the last valid (non-placeholder) selection and if changed to the placeholder, restore it back… but I doubt that’s worth doing.

Reading a bit closer, you seem not to want to do that, so… I dunno - can you maybe wait until a non-placeholder selection is made, and then remove the placeholder item from the model, preventing it being set again? GTK may not expect this kind of thing to happen though, so again, it might be more faff than is worthwhile :smiley:

Having tried to explain the problem to someone else and sleeping on it, I came up with two possible solutions: one involves creating a custom widget and the other is the initialisation of the DropDown during UI creation.

A Custom Widget :
I see this being constructed using GtkSwap with two pages, each with a GtkDropDow.

Page 0 (initial / default page) would have its DropDow displaying the list [‘- select -’, ‘Father’, ’ Mother’, ‘Child’, …].

Page 1 would have its DropDow displaying the list [‘Father’, ’ Mother’, ‘Child’, …], (and no ‘- select -’).

This would allow the creation of new entries when required, using page 0. For editing existing entries page 1 DropDow would be used. This approach would also allow more focused lists to be provided on other pages i.e. Where Father has already been entered a list could be limited to [‘Mother’, ‘Child’, ‘Grand Parent’, ‘Beneficiary’].

I haven’t considered this much further. However all the methods of DropDown may need to be duplicated.

Initialisation of the DropDown:
On instantiating the UI controller a datatclass is created which holds the selected DropDown value, among other values. When editing, the dataclass holds the existing value and is used to initialise the DropDown. The obvious thing to do for new entries, is to set the dataclass value first and then use it to initialise the DropDown. The initialisation value chosen being based upon querying previous saved entries.

This appears the obvious and simplest, solution and one I’m currently implementing.

Regards

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.