Two conditions inside an IF function
- vegard.grutle
- Posts: 59
- Joined: Fri Mar 17, 2017
Hi,
Im using the below script to hide / show a field:
I would also like the script to run if the following condition also is true:
How can I include two conditions inside the IF function?
Thanks in anticipation!
Vegard
Im using the below script to hide / show a field:
Code: Select all
if (fd.field('ContentType0').control('getSelectedText') == 'Complaint') {
$('div.fd_title').filter(function () { return $(this).text() === 'Root Cause (NCR/Complaint)' }).closest('tr').show();
$('div.fd_title').filter(function () { return $(this).text() === 'Basic Root Causes' }).closest('tr').hide();
}
else {
$('div.fd_title').filter(function () { return $(this).text() === 'Root Cause (NCR/Complaint)' }).closest('tr').hide();
$('div.fd_title').filter(function () { return $(this).text() === 'Basic Root Causes' }).closest('tr').show();
}
Code: Select all
if (fd.field('ContentType0').control('getSelectedText') == 'Non-confomance')
Thanks in anticipation!
Vegard
- Dmitry Kozlov
- Site Admin
- Posts: 1524
- Joined: Thu Jun 07, 2012
Hi,
You can join the conditions by using OR (||) operator:
https://www.w3schools.com/js/js_comparisons.asp
You can join the conditions by using OR (||) operator:
Code: Select all
if (fd.field('ContentType0').control('getSelectedText') == 'Complaint' ||
fd.field('ContentType0').control('getSelectedText') == 'Non-confomance') {...}
- vegard.grutle
- Posts: 59
- Joined: Fri Mar 17, 2017
Hi, Dmitry!
This works on the new form, but when loading the edit and display form both the fields ('Root Cause (NCR/Complaint)' and 'Basic Root Causes') are visible - see attachment.
Any ideas?
Vegard
This works on the new form, but when loading the edit and display form both the fields ('Root Cause (NCR/Complaint)' and 'Basic Root Causes') are visible - see attachment.
Any ideas?
Vegard
- Dmitry Kozlov
- Site Admin
- Posts: 1524
- Joined: Thu Jun 07, 2012
Please, note that the ContentType0 field must be located on the same form in order to check it's value via JavaScript. As for the display form, use the code below:
Code: Select all
if (fd.field('ContentType0').value() == 'Complaint' ||
fd.field('ContentType0').value() == 'Non-confomance') {...}
- vegard.grutle
- Posts: 59
- Joined: Fri Mar 17, 2017
Hi, again!
The 'ContentType0' is a visible on the form. The snip is only a small part of the form. I just noticed that when changing the value in the 'ContentType0' field (Lookup-field) which is a field that trigger some fields to hide/show after opening the editform the script is running as expected.
Any thoughts?
The 'ContentType0' is a visible on the form. The snip is only a small part of the form. I just noticed that when changing the value in the 'ContentType0' field (Lookup-field) which is a field that trigger some fields to hide/show after opening the editform the script is running as expected.
Any thoughts?
- Dmitry Kozlov
- Site Admin
- Posts: 1524
- Joined: Thu Jun 07, 2012
Hi,
So, as far as I understood, the code is executed when a user switches the value but it also should be executed when a user opens the form, am I right?
So, as far as I understood, the code is executed when a user switches the value but it also should be executed when a user opens the form, am I right?
- Dmitry Kozlov
- Site Admin
- Posts: 1524
- Joined: Thu Jun 07, 2012
OK, then just call the function containing your code outside of all handlers, ex:
Code: Select all
function myFunction() {
// you code with conditional hiding is here
}
// you call it inside a change handler:
fd.field('ContentType0').change(myFunction);
// you should also call it right here:
myFunction();
-
- Information
-
Who is online
Users browsing this forum: No registered users and 6 guests