hello, I have a DV with some Tabs, I set the code to hide or not a field based on a choice from the option list. the system works, but when I save and return to the Tabs, the hidden field reappears. how can I do ??
thanks
this a code on js file
$j(function(){
$j('#accompagnatore').on('change', function(){
if($j('#accompagnatore').select2('val') == 'NO'){
$j('#note_accompagnatore').parents('.form-group').hide();
}else{
$j('#note_accompagnatore').parents('.form-group').show();
$j('#note_accompagnatore').focus().select();
}
})
})
Problem with Hide Field on Tabs
Re: Problem with Hide Field on Tabs
You need something outside the onchange to init the page. The onchange just works off the change event and no event, no hide/show. It's basically that same code segment in the body of the onchange, the if block, but outside the onchange.
Try
$j(function(){
if($j('#accompagnatore').select2('val') == 'NO'){
$j('#note_accompagnatore').parents('.form-group').hide();
}else{
$j('#note_accompagnatore').parents('.form-group').show();
}
$j('#accompagnatore').on('change', function(){
if($j('#accompagnatore').select2('val') == 'NO'){
$j('#note_accompagnatore').parents('.form-group').hide();
}else{
$j('#note_accompagnatore').parents('.form-group').show();
$j('#note_accompagnatore').focus().select();
}
})
Try
$j(function(){
if($j('#accompagnatore').select2('val') == 'NO'){
$j('#note_accompagnatore').parents('.form-group').hide();
}else{
$j('#note_accompagnatore').parents('.form-group').show();
}
$j('#accompagnatore').on('change', function(){
if($j('#accompagnatore').select2('val') == 'NO'){
$j('#note_accompagnatore').parents('.form-group').hide();
}else{
$j('#note_accompagnatore').parents('.form-group').show();
$j('#note_accompagnatore').focus().select();
}
})
Re: Problem with Hide Field on Tabs
hi, thanks for your interest.
i inserted the code in my js file, but nothing does not work.
I don't know if it depends on the fact that this select is inside a tabs.
this is only code in table-dv.js
$j(function(){
if($j('#accompagnatore').select2('val') == 'NO'){
$j('#note_accompagnatore').parents('.form-group').hide();
}else{
$j('#note_accompagnatore').parents('.form-group').show();
}
$j('#accompagnatore').on('change', function(){
if($j('#accompagnatore').select2('val') == 'NO'){
$j('#note_accompagnatore').parents('.form-group').hide();
}else{
$j('#note_accompagnatore').parents('.form-group').show();
$j('#note_accompagnatore').focus().select();
}
})
i inserted the code in my js file, but nothing does not work.
I don't know if it depends on the fact that this select is inside a tabs.
this is only code in table-dv.js
$j(function(){
if($j('#accompagnatore').select2('val') == 'NO'){
$j('#note_accompagnatore').parents('.form-group').hide();
}else{
$j('#note_accompagnatore').parents('.form-group').show();
}
$j('#accompagnatore').on('change', function(){
if($j('#accompagnatore').select2('val') == 'NO'){
$j('#note_accompagnatore').parents('.form-group').hide();
}else{
$j('#note_accompagnatore').parents('.form-group').show();
$j('#note_accompagnatore').focus().select();
}
})
Re: Problem with Hide Field on Tabs
Hi,
you can try to set a timer to see if it is because the select2 element does not yet exist.
you can try to set a timer to see if it is because the select2 element does not yet exist.
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: Problem with Hide Field on Tabs
Thanks to Ahmed (UDEMY COURSE) to resolve it.
this is the code to resolve my problem.
The above code will make a check every 500 msec for the value of the drop-down and hide/show the field accordingly.
this is the code to resolve my problem.
Code: Select all
$j(function(){
setInterval(function() {
if(
$j('#accompagnatore').select2('val') == 'NO' &&
!$j('#note_accompagnatore').parents('.form-group').hasClass('hidden')
) {
$j('#note_accompagnatore').parents('.form-group').addClass('hidden');
}
if(
$j('#accompagnatore').select2('val') != 'NO' &&
$j('#note_accompagnatore').parents('.form-group').hasClass('hidden')
) {
$j('#note_accompagnatore').parents('.form-group').removeClass('hidden');
$j('#note_accompagnatore').focus().select();
}
}, 500);
})