Hi,
I have followed the example in the "React to lookup changes" section, but in my case only "fade in common fields" is executing. The other part of the code is not working. Can someone explain to me where I make a mistake? Also my programming skills are poor. I attached the .axp and .js files.
Thanks in advance!
React to lookup changes - No working
-
- Posts: 6
- Joined: 2017-08-26 15:39
React to lookup changes - No working
- Attachments
-
- Test_DB.zip
- (14.49 KiB) Downloaded 74 times
Re: React to lookup changes - No working
- Did you clear browser cache when reloading?
- Are there any error messages in console output?
https://appgini.bizzworxx.de/support/troubleshooting/
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
-
- Posts: 6
- Joined: 2017-08-26 15:39
Re: React to lookup changes - No working
Sure, but it is not working. Maybe I don't understand the way the code is supposed to work. As you can see "Елемент" is with id =3. "combine_prt,type_of_module" should hide when this id is selected. In my case when nothing is selected everything is hidden, and when I press id 1 or id 2 only fields "stock, quantity, price" are visible.
- Attachments
-
- used_items2.png (32.29 KiB) Viewed 8574 times
-
- used_items.png (198.07 KiB) Viewed 8574 times
Re: React to lookup changes - No working
I strongly recommend adding more console output commands (console.log("..."); ) for printing out the variable values you get using .getValue() function and also for printing out the values of your option_x_is_selected variables. As soon as you can see the variable values, you will see if your function gets executed at all and if your conditions really evaluate what you expect.
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: React to lookup changes - No working
I don't know your specific use case and your expectation of which fields to hide and which fields to show under which conditions.
But I have seen you are using both, "fade" and "hide" function. Keep in mind that hide has opposite function than fade/show:
If, for example...
...then...
...will show the field "a" but hide the field "b"
But I have seen you are using both, "fade" and "hide" function. Keep in mind that hide has opposite function than fade/show:
- fade(true) shows the field
same as fadeIn() without parameters - fade(false) hides the field
same as fadeOut() without parameters
- hide(true) hides the field
same as hide() without parameters - hide(false) shows the field
- show(true) shows the field
same as show() without parameters - show(false) hides the field
If, for example...
Code: Select all
var condition1 = true;
Code: Select all
dv.getField("a").fade(condition1);
dv.getField("b").hide(condition1);
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
-
- Posts: 6
- Joined: 2017-08-26 15:39
Re: React to lookup changes - No working
Ok thanks for the examples, I did not understood how "hide, fade" worked.
Can you explain to me how I can create the following logic:
I would like to create a cascade show/hide fields depending on the value (id) of the drop-down menu.
For example if you have a warehouse where you store a lot of different things categorized like so ("Modules, measuring equipment, elements"). In my case I created a table where I can use it in a couple of places. Imagine you repaired something but you used different types of components ("Capacitors, Resistors etc."). Depending on the choice different fields need to show and others to hide.
Example: If you pick from "Type" -> (Elements) only one field needs to show "Type of element". If you pick "Capacitors" only "combine_cap" need to show. The fields that need to be constantly shown are "Stock, Quantity, Price".
I have tried the logic described in "React to lookup changes" but I could not figure it out.
I need to apologies about my bad programming skills and it will be awesome if you can show me a example of such logic.
Thanks in advance!
Can you explain to me how I can create the following logic:
I would like to create a cascade show/hide fields depending on the value (id) of the drop-down menu.
For example if you have a warehouse where you store a lot of different things categorized like so ("Modules, measuring equipment, elements"). In my case I created a table where I can use it in a couple of places. Imagine you repaired something but you used different types of components ("Capacitors, Resistors etc."). Depending on the choice different fields need to show and others to hide.
Example: If you pick from "Type" -> (Elements) only one field needs to show "Type of element". If you pick "Capacitors" only "combine_cap" need to show. The fields that need to be constantly shown are "Stock, Quantity, Price".
I have tried the logic described in "React to lookup changes" but I could not figure it out.
I need to apologies about my bad programming skills and it will be awesome if you can show me a example of such logic.
Thanks in advance!
Re: React to lookup changes - No working
Sorry, I cannot do the job, but I can send a few examples* for better understanding.
Example (1)
Show field "a" only if type.id equals 1
Shorter version
---
Example (2)
Show field "a" if type.id equals 1
Show field "b" if (type.id equals 1) AND ((category.id equals 12) OR (category.id equals 14))
Shorter version
Debugging
I recommend adding as many console.log("..."); commands as necessary during development. This allows you to check the content of your variables if something does not work as expected, for example:
Notes about conditions
In javascript (and many other programming languages)...
More on conditions
Example (1)
Show field "a" only if type.id equals 1
Code: Select all
var type_field = dv.getField("type");
var type_id = type_field.getValue().id;
if (type_id == 1) {
dv.getField("a").show();
} else {
dv.getField("a").hide();
}
Code: Select all
var type_id = dv.getField("type").getValue().id;
dv.getField("a").show(type_id == 1);
Example (2)
Show field "a" if type.id equals 1
Show field "b" if (type.id equals 1) AND ((category.id equals 12) OR (category.id equals 14))
Code: Select all
var type_field = dv.getField("type");
var type_id = type_field.getValue().id;
var category_field = dv.getField("category");
var category_id = category_field.getValue().id;
var a_field = dv.getField("a");
var b_field = dv.getField("b");
if (type_id == 1) {
a_field.show();
if (category_id == 12) {
b_field.show();
} else if (category_id == 14) {
b_field.show();
} else {
b_field.hide();
}
} else if (type_id==2) {
b_field.show();
} else {
a_field.hide();
b_field.hide();
}
Code: Select all
var type_id = dv.getField("type").getValue().id;
var category_id = dv.getField("category").getValue().id;
// evaluate conditions
// I have added unnecessary brackets for better readability
var show_field_a = (type_id == 1);
var show_field_b = (type_id == 1) && ( (category_id == 12) || (category_id == 14) );
// show fields "a", "b" under certain conditions:
dv.getField("a").show(show_field_a);
dv.getField("b").show(show_field_b);
I recommend adding as many console.log("..."); commands as necessary during development. This allows you to check the content of your variables if something does not work as expected, for example:
Code: Select all
var type_id = dv.getField("type").getValue().id;
var category_id = dv.getField("category").getValue().id;
console.log("type_id = " + type_id);
console.log("category_id = " + category_id);
// note: getValue() function for lookup fields returns not just the id, but an ...
// object which contains both: id and text
var type_value = dv.getField("type").getValue();
console.log("type:");
console.log(type_value);
console.log("type.id = " + type_value.id);
console.log("type.text = " + type_value.text);
In javascript (and many other programming languages)...
- "&&" means "AND"
- "||" means "OR"
- "==" means "EQUALS"
Code: Select all
var a = 1; // assignment
// declare variable "a", assign value 1 to variable "a"
var b = (a == 1); // declare variable "b", evaluate condition, then assign result to variable "b"
// first, evaluate expression ("if a equals 1"). This gives true. Then assign the result (true) to variable "b"
console.log(a);
console.log(b);
// console output:
// 1
// true
- operators: https://www.w3schools.com/js/js_comparisons.asp
- if..then..else: https://www.w3schools.com/js/js_if_else.asp
- Bool: https://www.w3schools.com/js/js_booleans.asp
- Switch: https://www.w3schools.com/js/js_switch.asp
- Assignment: https://www.w3schools.com/js/js_assignment.asp
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
-
- Posts: 6
- Joined: 2017-08-26 15:39
Re: React to lookup changes - No working
Hi,
Thanks for the examples, I learned a lot from them. Now I have the following problem: According to the console "getValue().id" has no value. Here I attach a picture from the console and the code.
//code begin
var dv = AppGiniHelper.DV;
dv.ready(onReady);
function onReady() {
type_init();
}
function type_init() {
var type_field = dv.getField("type");
var type_id = type_field.getValue().id;
var currentvalue = type_id;
hideOrShowFields(currentvalue);
field.onChange(onTypeIdChanged);
}
function onTypeIdChanged(value) {
hideOrShowFields(value);
}
function hideOrShowFields(value) {
if (type_id == 1) {
dv.getField("type_of_module").show();
} else {
dv.getField("type_of_module").hide();
}
console.log("type_id = " + type_id);
}
//code end
Best regards!
Thanks for the examples, I learned a lot from them. Now I have the following problem: According to the console "getValue().id" has no value. Here I attach a picture from the console and the code.
//code begin
var dv = AppGiniHelper.DV;
dv.ready(onReady);
function onReady() {
type_init();
}
function type_init() {
var type_field = dv.getField("type");
var type_id = type_field.getValue().id;
var currentvalue = type_id;
hideOrShowFields(currentvalue);
field.onChange(onTypeIdChanged);
}
function onTypeIdChanged(value) {
hideOrShowFields(value);
}
function hideOrShowFields(value) {
if (type_id == 1) {
dv.getField("type_of_module").show();
} else {
dv.getField("type_of_module").hide();
}
console.log("type_id = " + type_id);
}
//code end
Best regards!
- Attachments
-
- Console.png (153.5 KiB) Viewed 8474 times
Re: React to lookup changes - No working
Hi,
have a look at the error message which shows the reason.
If there is no selection, .getValue()-function can not return an object having properties id and text but getValue() returns null instead.
You have to check if the return value equals null. If it equals null, there cannot be an .id nor .text property.
Long version
Shorter version
have a look at the error message which shows the reason.
If there is no selection, .getValue()-function can not return an object having properties id and text but getValue() returns null instead.
You have to check if the return value equals null. If it equals null, there cannot be an .id nor .text property.
Long version
Code: Select all
var type_field = dv.getField("type");
var type_value = type_field.getValue();
if (type_value != null) {
var type_id = type_value.id;
//
} else {
// whatever you want to do if type is empty
}
Code: Select all
var type_value = dv.getField("type").getValue();
var type_id = type_value != null ? type_value.id : 0;
// type_id:
// 0 if there is no selection
// n if there is a selection (n: primary key of selected lookup entry)
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