Show or hide control according to values of a field

Hello!! I have a field with optional answers and text notes that are shown or not depending on
the answers marked.

The following code works fine but I need that when the optional field has nothing marked (it is blank) no note is displayed and I don't know how to add that without breaking my code.

thank you

function showHideNote() {
console.log(fd.field('FormaJuridica').value);
if(fd.field('FormaJuridica').value =='Persona Física'){
$('.OcultarMostrar2').hide();
$('.OcultarMostrar').show();
}
else {
$('.OcultarMostrar').hide();
$('.OcultarMostrar2').show();
}
}

fd.rendered(function () {
$('.OcultarMostrar').hide();
$('.OcultarMostrar2').hide();
//сalling the function on form load
showHideNote();
//Call the function when the field value changes
fd.field('FormaJuridica').$on('change', showHideNote);

});

I was able to fix it!! I checked with the state type null

Thank you very much, I leave it here in case someone needs it

function showHideNote() {
console.log(fd.field('FormaJuridica').value);
if(fd.field('FormaJuridica').value =='Persona Física'){
$('.OcultarMostrar2').hide();
$('.OcultarMostrar').show();
}
else if(fd.field('FormaJuridica').value == null){
$('.OcultarMostrar2').hide();
$('.OcultarMostrar').hide();
}
else {
$('.OcultarMostrar').hide();
$('.OcultarMostrar2').show();
}
}

fd.rendered(function () {

//сalling the function on form load
showHideNote();
//Call the function when the field value changes
fd.field('FormaJuridica').$on('change', showHideNote);

});

1 Like