Problem with Hide Field on Tabs

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
lzonca
Posts: 16
Joined: 2019-03-11 14:48

Problem with Hide Field on Tabs

Post by lzonca » 2020-06-04 16:17

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();
}
})
})

pfrumkin
Veteran Member
Posts: 157
Joined: 2020-02-18 17:58
Location: Albuquerque, New Mexico USA

Re: Problem with Hide Field on Tabs

Post by pfrumkin » 2020-06-04 20:07

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();
}
})

lzonca
Posts: 16
Joined: 2019-03-11 14:48

Re: Problem with Hide Field on Tabs

Post by lzonca » 2020-06-06 16:23

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();
}
})

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1638
Joined: 2018-04-01 10:12

Re: Problem with Hide Field on Tabs

Post by pbottcher » 2020-06-06 17:24

Hi,

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.

lzonca
Posts: 16
Joined: 2019-03-11 14:48

Re: Problem with Hide Field on Tabs

Post by lzonca » 2020-06-19 16:07

Thanks to Ahmed (UDEMY COURSE) to resolve it.
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);
})
The above code will make a check every 500 msec for the value of the drop-down and hide/show the field accordingly.

Post Reply