Hi all,
I likely am way of with this but I am trying to show hide a field or two based on one value from a lookup field. I thought I would create a tablename-dv.js file with the following code in it. I have tried both text and a numerical value of the text selection. Neither works:
$j(document).ready(function(){
$j('#My_Field').change(function() {
if($j('#My_Field').text()=="This Value")
$j('#ScID').show();
else
$j('#ScID').hide();
})
})
I have used the code from Ahmed's tutorials but it does the opposite and hides the field when the lookup is selected:
$j(function(){
$j('#My_Field').on('change', function(){
var IR = parseFloat($j(this).val());
if(IR == 'This Value'){
$j('#ScID').parents('.form-group').show();
}else{
$j('#ScID').parents('.form-group').hide();
}
});
});
I am not sure what I have to do, I did try and use the value of the selection (7) as well.
Show/Hide field based on lookup
Re: Show/Hide field based on lookup
Hi Kevin,
if you need only to check for the change you can use:
replace My_Field by your fieldname and MYVALUE by the selected item from the lookup.
if you need only to check for the change you can use:
Code: Select all
$j(function(){
$j('#My_Field').on('change', function(){
var IR = $j('#s2id_My_Field-container .select2-chosen').text());
if(IR == 'MYVALUE'){
$j('#ScID').parents('.form-group').show();
}else{
$j('#ScID').parents('.form-group').hide();
}
});
});
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.
Re: Show/Hide field based on lookup
Hi,
I substituted my values and it works in reverse, every selection hides the ScID field. Ideally the field stays hidden and selecting 'Safety Concern' shows the ScID field:
$j(function(){
$j('#Inspection_Reason').on('change', function(){
var IR = $j('#s2id_Inspection_Reason-container .select2-chosen').text();
if(IR == 'Safety Concern'){
$j('#ScID').parents('.form-group').show();
}else{
$j('#ScID').parents('.form-group').hide();
}
});
});
I substituted my values and it works in reverse, every selection hides the ScID field. Ideally the field stays hidden and selecting 'Safety Concern' shows the ScID field:
$j(function(){
$j('#Inspection_Reason').on('change', function(){
var IR = $j('#s2id_Inspection_Reason-container .select2-chosen').text();
if(IR == 'Safety Concern'){
$j('#ScID').parents('.form-group').show();
}else{
$j('#ScID').parents('.form-group').hide();
}
});
});
Re: Show/Hide field based on lookup
Hi,
not sure what the issue is. Every selection (apart "Safety Concern") will hide the ScID. Only if you select the Safety Concern, it will be shown.
This does of course not work for the initial load of the page, as you react with the "on('change'..) only on changes to the fieldvalue.
If you want to hide field once the page gets loaded, you need to check for the value at the time the page is loaded and set the field status accordingly.
not sure what the issue is. Every selection (apart "Safety Concern") will hide the ScID. Only if you select the Safety Concern, it will be shown.
This does of course not work for the initial load of the page, as you react with the "on('change'..) only on changes to the fieldvalue.
If you want to hide field once the page gets loaded, you need to check for the value at the time the page is loaded and set the field status accordingly.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.
Re: Show/Hide field based on lookup
Yes,
Once I click on the drop down the field disappears and doesn't come back. LOL.
Once I click on the drop down the field disappears and doesn't come back. LOL.