Hello,
I have the following problem:
I have a table that should take over a value from another table via the lookup function. This works very well with the standard means.
Now I want to set the default value of the lookup field to $memberInfo["custon"][3]; when entering a record ...
I do this in the .php of the table file under:
* Called when a user requests to view the detail view (before displaying the detail view).
function verein_dv($selectedID, $memberInfo, &$html, &$args) {
if (!$selectedID) {
$fieldname = "user";
$default = $memberInfo["custom"][3];
$html .= '<script>$j("#' . $fieldname . '").val("' . $default . '");</script>';
}
}
Unfortunately, this doesn't work if the field is a lookup field. If I use a text field instead of a lookup field, assigning the default value works fine.
Thanks for the help !
Christian
lookup field - default value
Re: lookup field - default value
Hello,
can anyone help me with a solution or a solution approach ?
Thank you and have a nice day
Christian
can anyone help me with a solution or a solution approach ?
Thank you and have a nice day
Christian
Re: lookup field - default value
Since no one was able to help you with a standard solution for many months now, I would like to show how this can be done using latest version of AppGini Helper Javascript Library (commercial, I am the author).
If you only know the id (primary key):
If you know both, id (primary key) and text
Result
PS: I hope nobody feels offended by the fact that I show a solution which requires an additional product. At least this solution should help those AppGineers who are already using my library.
PPS: The
If you only know the id (primary key):
Code: Select all
// file: hooks/TABLENAME-dv.js
AppGiniHelper.DV.waitForAllFields(function() {
const fieldname = "project_id";
const field = AppGiniHelper.DV.getField(fieldname);
// we only know the id:
var id = 3;
// request id and text from the server, then change the field's value
field.lookupText(id, function(value) {
if (value.id) field.setValue(new AppGiniLookupValue(value.id, value.text));
});
});
Code: Select all
// file: hooks/TABLENAME-dv.js
AppGiniHelper.DV.waitForAllFields(function() {
const fieldname = "project_id";
const field = AppGiniHelper.DV.getField(fieldname);
// we know both, id and text
var id = 3;
var text = "ERP"
// just change the field's value
field.setValue(new AppGiniLookupValue(id, text));
});
PS: I hope nobody feels offended by the fact that I show a solution which requires an additional product. At least this solution should help those AppGineers who are already using my library.
PPS: The
field.setValue()
function works for normal input fields and also for lookup fields. For lookups we have to pass an object having id
and text
property. For inputs you can just pass the simple value. It is the same for field.getValue()
function, which returns a simple value or an object (having id
and text
), depending on the field type.Kind regards,
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
AppGini 24.10 Revision 1579 + all AppGini Helper tools
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
[code]...[/code]
blocks for better readabilityAppGini 24.10 Revision 1579 + all AppGini Helper tools
Re: lookup field - default value
Thank you very much !
I have the AppGini Helper Javascript Library in use and will test that right away.
Thank you and have a nice weekend
I have the AppGini Helper Javascript Library in use and will test that right away.
Thank you and have a nice weekend
Re: lookup field - default value
Thank you very much - works perfectly.
A supplementary question.
I use an extended "user settings table" along these lines:
viewtopic.php?f=4&t=4262&p=17059&hilit= ... ser#p16929
From this table I want to read the values for the "var id" and "var text".
Where and how do I do this best ?
Thanks for the help.
When I have solved this problem, my project will be finished
A supplementary question.
I use an extended "user settings table" along these lines:
viewtopic.php?f=4&t=4262&p=17059&hilit= ... ser#p16929
From this table I want to read the values for the "var id" and "var text".
Where and how do I do this best ?
Thanks for the help.
When I have solved this problem, my project will be finished
Re: lookup field - default value
Easiest would probably be fetching required data in _dv hook using PHP and then adding a Javascript-<script> to $html variable which declares those two Javascript variables.
Kind regards,
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
AppGini 24.10 Revision 1579 + all AppGini Helper tools
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
[code]...[/code]
blocks for better readabilityAppGini 24.10 Revision 1579 + all AppGini Helper tools