Dependent Dynamic Fields - Selected values cannot be saved or submitted

Moderator: crythias

Locked
cryptoroot
Znuny newbie
Posts: 26
Joined: 10 Jul 2014, 19:58
Znuny Version: 4.0.3
Real Name: Jorge Rojas
Company: Instituto Costarricense de Electricidad
Location: Costa Rica

Dependent Dynamic Fields - Selected values cannot be saved or submitted

Post by cryptoroot »

I have loaded 2 dynamic fields from a db using as a reference this post: viewtopic.php?t=17033. The first one (Provincia) was filled manually.
Image

Dynamic Fields Canton and Distrito are dependent, and load perfectly when I select or change each other. I used this code:

Code: Select all

#PROVINCIA
 <script type="text/javascript">//<![CDATA[
     $('#DynamicField_Provincia').bind('change', function (Event) {
         Core.AJAX.FormUpdate($('#NewEmailTicket'), 'AJAXUpdate', 'PriorityID', [ 'TypeID', 'Dest', 'NewUserID','NewResponsibleID', 'NextStateID', 'ServiceID', , 'SLAID', 'SignKeyID', 'CryptKeyID', 'To', 'Cc', 'Bcc', 'StandardTemplateID', 'DynamicField_Provincia', 'DynamicField_Canton', 'DynamicField_Distrito']);
						switch ( $('#DynamicField_Provincia :selected').text() ) {
                    case "San Jose":      
                        var request = $.ajax({
						type: 'GET',
						url: 'cantones.pl?q=' + 'San Jose',
						dataType: 'html'
						});
						request.done( function(data){
						$('#DynamicField_Distrito').empty();
						$('#DynamicField_Canton').empty();
						$('#DynamicField_Canton').append(data);						
													});
                    break;
                     case "Alajuela":      
                        var request = $.ajax({
						type: 'GET',
						url: 'cantones.pl?q=' + 'Alajuela',
						dataType: 'html'
						});
						request.done( function(data){
						$('#DynamicField_Distrito').empty();
						$('#DynamicField_Canton').empty();
						$('#DynamicField_Canton').append(data);
													});
                    break;
                    .
                    .
                    .
#CANTON
 <script type="text/javascript">//<![CDATA[    
	$('#DynamicField_Canton').bind('change', function (Event) {
	         Core.AJAX.FormUpdate($('#NewEmailTicket'), 'AJAXUpdate', 'PriorityID', [ 'TypeID', 'Dest', 'NewUserID','NewResponsibleID', 'NextStateID', 'ServiceID', , 'SLAID', 'SignKeyID', 'CryptKeyID', 'To', 'Cc', 'Bcc', 'StandardTemplateID', 'DynamicField_Provincia', 'DynamicField_Canton', 'DynamicField_Distrito']);
		var canton = $('#DynamicField_Canton :selected').text();
		$("#DynamicField_Canton").val($('#DynamicField_Canton :selected').val());
		var request = $.ajax({
		type: 'GET',
		url: 'distritos.pl?q=' + canton,
		dataType: 'html'
						});
    	request.done( function(data){
		$('#DynamicField_Distrito').empty();
		$('#DynamicField_Distrito').append(data);
});
    });
//]]></script>

#DISTRITO
 <script type="text/javascript">//<![CDATA[    
	$('#DynamicField_Distrito').bind('change', function (Event) {
	         Core.AJAX.FormUpdate($('#NewEmailTicket'), 'AJAXUpdate', 'PriorityID', [ 'TypeID', 'Dest', 'NewUserID','NewResponsibleID', 'NextStateID', 'ServiceID', , 'SLAID', 'SignKeyID', 'CryptKeyID', 'To', 'Cc', 'Bcc', 'StandardTemplateID', 'DynamicField_Provincia', 'DynamicField_Canton', 'DynamicField_Distrito']);
		$("#DynamicField_Distrito").val($('#DynamicField_Distrito :selected').val());
    });
//]]></script>                    
When I change Provincia, I can see that reflected in the HTML code
Image

But not the same situation when I change Canton or Provincia, doesn't add the selected attribute.
Image

I guess for this reason, when I submit the ticket, I get an error that say "The field content is invalid" and change the 2 dependent fields in color red, empty.

Someone has faced with this issue or knows a fix. I really appreciate help, I have days trying to resolve the problem.
You do not have the required permissions to view the files attached to this post.
Locked