Hello!
I am trying to show/hide a container based on dinamic dropdown selection. I tried to follow this post, but after several days and for any reason it doesn't work. I will apreciate your help!
This is what I did:
Designer
A dropdown field with the following configuration:
A container with the following configuration:
Inside the container, a dropdown field with this configuration:
Setup
On load event
DB Read action with:
Model ID: Medio
Conditions:
Load JavaScript action with:
On ajax event
DB Read action with:
Model ID: Data
Conditions:
Custom Code action with:
I am trying to show/hide a container based on dinamic dropdown selection. I tried to follow this post, but after several days and for any reason it doesn't work. I will apreciate your help!
This is what I did:
Designer
A dropdown field with the following configuration:
Gemeral tab:
Field Name: elige_medio
Field ID: elige_medio
Dinamic Data tab:
Enabled: Yes
Data Path: Medio
Value key: medio_corto
Text key: medio
Events tab:
On = | '' | Set Options | dropdown_respuesta | =No hay seleccion
On != | '' | Set Dynamic Options | dropdown_respuesta | ajax
A container with the following configuration:
Label: chronoform-container-26
Type: DIV
Title: Container #26
ID: chronoform-container-26
Class: chronoform-container
Load state: Visible
Inside the container, a dropdown field with this configuration:
General tab:
Field Name: dropdown_respuesta
Field ID: dropdown_respuesta
Setup
On load event
DB Read action with:
Model ID: Medio
Conditions:
<?php
return array('Medio.activo' => '1');
?>
Load JavaScript action with:
jQuery(document).ready(function (jQ) {
jQ('#chronoform-container-26').hide();
jQ('#elige_medio').change(function () {
var opt;
opt = jQ(this).find(':selected').data('Medio.con_pregunta').toString();
if (opt.length > 0) {
jQ('#chronoform-container-26').show();
} else {
jQ('#chronoform-container-26').hide();
}
});
});
On ajax event
DB Read action with:
Model ID: Data
Conditions:
<?php
return array( 'medio_corto' => $form->data['elige_medio'] );
?>
Custom Code action with:
<?php
$options = array();
if ( !$form->data['Data'] || count($form->data['Data']) < 1 ) {
// no result was found
$options[] = 'Seleccione Medio/Gremio';
} else {
$options = array($form->data['Data']['pregunta'], $form->data['Data']['respuesta1'], $form->data['Data']['respuesta2'], $form->data['Data']['respuesta3']);
}
echo json_encode($options);
?>