Using two valuelists on one field

Hi,

I am struggling with a problem for several days now and I wonder if anyone has a bright idea :

I have a field on a form that has a value list attached containing two fields :
(person_id (stored) , person_name (displayed))

But : I want the value list to be different for browse+find versus new+add mode

In new+add mode the list should contain a subset of all values.
In browse+find mode the list should contain all values.

(The subset (limited list) should contain only values that are actual (for instance only currently employed salesmen) and are related to another field in the same table (for instance only salesman for a specific business unit))

The complete set (all list) should contain all values so you can search on a salesman that is no longer employed and for whom you do not know the business unit.

I only want the limited list to be activated when the user selects the combobox.
In all other situations the all list should be active.

I tried several scenarios and will explain two of them here:

  1. using two fields with the same dataprovider, one with the all list attached and one with the limited list attached.
    Setting one field visible/one field invisible depending on the mode.
    This will not work if you want the limited list to be applied when the user selects the combobox.
    You would have to use the onFocusGained/Lost events to change the visible field, which is a difficult/strange combination (focus and visible)

  2. using one field with an empty value list attached.
    Creating two datasets and attach the correct dataset to the value list depending on the mode.
    This can also be done in an onFocusGained/Lost event.

Is the second the best way or is there another way to do this ?

I hope this makes sense, it is rather complex and hard to explain.

Regards,

Hi Hans, I know exactly what you mean!

we also, bump into this, with using comboboxes (with valuelist) showing values and returning ID’s
for instance with projects, we only would like to show, active projects, but if we do that, old in-active projects will show only the ID, in the field.

we discussed this at our DUG meeting. last year in Houten (which you attended also :-) )

and asked Jan Blok, if we could get this as a feature. Don’t know the status, but will ask him.

Hi Harjo,

I suppose i did not know as much then about Servoy as I do now and did not understand the discussion then.
Or I have forgotten about it (reached the age of 53 today so maybe the old memory is dereasing ??)

Thanks anyway.

B.t.w. I think Jan Blok is on Holiday now.

Regards,

B.t.w. I think I found a solution that might do the trick.

Create a valuelist based on a global relation.
Create this global relation with two global variables (actual y/n and business unit) and set these variables in the onFocusGained and onFocusLost event of the combobox.

Will test this tomorrow and let you know.

Otherwise option 2 from my initial post will have to do.

Have to celibrate a birthday now.

Regards,

Hi,

Did the test with a valuelist based on a global relation and then change the global vars eather to a subset or to all values.

I set these global vars in the onFocusGained and onFocusLost events of the combobox.

When I select the combobox the correct subset is shown in the valuelist.
If I do a find all values are shown in the valuelist.

One problem ocurred and that is that the field is not showing the current value if you change the underlying relation of the valuelist.

If I do a nextrecord/previous record ( or a relookup of the current record) the current value is shown.

I created a case for this in the support system.

ALTERNATIVE WAY TO DO THIS :

I also tested using an empty valuelist attached to the combobox and
then setting the values in the list by using two different queries (all/subset) and using :

  • databaseManager.getDataSetByQuery
  • application.setValueListItems

Again using the onFocusGained/onFocusLost events of the combobox.
This also works and the “display” problem does not occur then.

But using a global relation feels more like the “Servoy” way.

Hi,

Regarding the case : “field is not showing the current value if you change the underlying relation of the valuelist” :

Status: closed-fixed
Resolution:
Fixed. Will be included in next public release of Servoy.

Thanks Servoy, for the speedy fix.

I am having this exact problem in my application. I struggled first then went to the forum… Should have done the opposite when I first found the issue and I wouldn’t have struggled so much!

Servoy Developer
Version 3.5.7-build 520
Java version 10.0-b19 (Windows XP)

Agree !!

I also look in the forum first now when i encounter a problem or have a question.

Lots and lots of info and helpfull people there.

Regards,

Hi Harjo,

Did you discuss this with Jan Blok ??

What kind of workaround are you using now ?

I tought i had a solution (as mentioned before), but in listview the comboboxes go empty when i change
the underlying relation in a way that the valuelist does not contain the id in the combobox.

In Recordview it works fine.

I am planning to do a feature request for valuelists.
I liked the way the previous tool i was working with solved this.

Regards,

yes the “fix” we did to get it working on RecordView was not really a fix
it was more of a quick hack around the fact that we did have for 1 moment in time still a selected display value

But for table/list view this will never work because if a setValue() is called (which will happen all the time on table/list to render the value)
the display is really gone or we really dont know that the previous selected display was really the display of the value we just got.
So then we really lost the display value.

So for this we really need to change or add properties to the repository/solution model because currently there is just no way for us to do it.

I guess we could have something like 2 valuelists but now if i read this thread there could even be 3??
Or is 1 reusable?

1> the normal valuelist (edit/new)
2> the “all” valuelist to get a display value for the selected real value…
3> the find valuelist, or can this just be 2? Is it almost always that same all valuelist? (ofcourse this all valuelist could be set just before and after find…)

Hi Johan,

No, there are only two valuelists : a list with all values (for browse/find) and a list with the curently allowed values (for edit/new).

What would be relay nice is a combobox with a valuelist attached, that displays a name and returns only the id to the combobox.
So, it does not display the name in the combobox !!!
The combobox in its turn must be a releated field which points to the namefield of the related table based on the id.
This way, the name is always displayed, no mather what valuelist is attached.

I have build this by using two fields : one combobox (dataprovider is person_id) with a valuelist attached (person_id,person_name)
person_id is returned and person_name is displayed in the combobox.

On top of the combobox i put another field, dataprovider is a related field that points to the person_name in the person table, based on the same pers_id field. So the combobox and the extra field always have the same (pers_id) value.

The extra text_field is exactly on top of the combobox, only it leaves the selection arrow free.
So if i click the arrow, the valuelist for the combobox is displayed.
If i select a value i do not see it in the combobox, because that is hidden by the extra field.
But since the extra field has the same dataprovider(pers_id) and a relation to the name, i see the selected pers_name in the exta field.
The user does not even notice that the extra field is there.

In list mode/table mode, if there are values in the combobox that are not in the valuelist, these comboboxes will be empty.
But that does not matter, because the extra field on top of the combobox still shows the correct value for pers_name.

The only issue i ran into was when you do a find.
Because if you select a value in the combobox in find mode, the extra field that is on top is not showing the selected value,
so that looks strange to the user. He selects a value in the lists and it does not show up in the field.
Altough the search is done as aspected based on the choosen pers_id value.

Is solved this by setting the extra field to transparent when in find mode and back to none-transparent after the search.

I have some ideas about valuelists, also based on expirience with previous tools i used.
Maybe we can discuss this when i visit Amersfoort the next time ?

Regards,

i dont know what you exactly mean by:

What would be relay nice is a combobox with a valuelist attached, that displays a name and returns only the id to the combobox.
So, it does not display the name in the combobox !!!

Did you guys try a TypeAhead field?

It is hard to explain by writing.

I would like a valuelist (id,name) on a field, that lets you select a value based on the name.

It should then only return the id to the field. So it should not “translate” the id to the name.
So if it would be a normal textfield, you would only see the id after a selection from the valuelist.

But , the field that the list is attached to is a related field. It displays a persons name based on the id.

This way you have a field with a valuelist, but the value that is displayed in the field is not dependend
on that valuelist. If the id in the field does not exist in the valuelist, the correct name is still displayed.
Even in List/Table view.

I was used to this way of working in the previous tool i used.
There you could define a query and the result was shown in a kind of dialogue form.
You could search on the contents of alle columns that where retreived by the query.
And then you could select one row of the remaing rows.
You could also define what should happen to all the colums of the row you selected in this
“dialogue”. So you could say :
contents of column 1 goes to field a
contents of column 2 goes to field b
contents of column 3 is only informational and is not returned to a field
etc.

This would work in edit mode and in find mode.

We are now doing that in Servoy by using form in dialogue as a “search/select” select form. This works oke, only NOT in find mode.

Regards,