modifying the behavior of the detail view via js

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
wplim
Veteran Member
Posts: 36
Joined: 2013-01-17 22:42

modifying the behavior of the detail view via js

Post by wplim » 2015-03-09 21:24

I have a solution build in v5.12 with the following js in hooks folder. After moving to v5.31 the scripts is no longer working.
'Asy' is a dropdown field. When user select '3', 'Cell' another dropdown field changes to 'TST', and 'Priority' dropdown field changes to 99.

Code: Select all

document.observe('dom:loaded', function() {
    $('Asy').observe('change', function() {
		if($F('Asy') == 3){
			$('Cell').value = 'TST';
			$('Priority').value = 99;
			$('Asy').focus();
        }
    });
});
I came across other postings regards to jQuery, so I tried the following:

Code: Select all

jQuery(function(){ 

    jQuery('#Asy').on('change', function() {
		
		if(jQuery('#Asy').val() == 3){
			alert('detected'); // pop up if Asy change to '3'
			jQuery('#Cell').val('TST'); // not working for dropdown but works if change to input
			jQuery('#Priority').val(99); // not working for dropdown but works if change to input
			jQuery('#Asy').focus();
        }
			
    });
});
However, the code to change the value of a dropdown field is not working. Have anyone encounter similar issue?

Perhaps a tutorial similar to http://bigprof.com/appgini/help/advance ... agic-files would be very helpful.

Thank you.

Weoi

wplim
Veteran Member
Posts: 36
Joined: 2013-01-17 22:42

Re: modifying the behavior of the detail view via js [solved

Post by wplim » 2015-03-10 23:51

Update

I have tried with the following code: (referring to https://select2.github.io/examples.html Programmatic access

Code: Select all

jQuery('#Cell-container').val('TST').trigger("change");  
Firebug shows:
TypeError: e.added is undefined
current_Cell.value = e.added.id;

apparently this only works on select2 ver 4

further digging on v3.5.2 documentation

I try the set val method:

Code: Select all

jQuery('#Cell-container').select2('val','TST');


Nothing happen, no js error. Cell still shows "ASY" which is the original value, but when open the drop down list, "TST" is highlighted. Very strange.

Next try set data method:

Code: Select all

jQuery('#Cell-container').select2('data',{id: 'TST', text: 'TST'});
This works!!!! :D

Diogenes
Posts: 16
Joined: 2015-05-07 14:03

Re: modifying the behavior of the detail view via js

Post by Diogenes » 2015-05-07 14:06

Would you please now provide all of the code that is now working?

I had to guess and this is what I came up with: is this correct?

Code: Select all

jQuery(function(){

    jQuery('#Asy').on('change', function() {
      
      if(jQuery('#Asy').val() == 3){
         alert('detected'); // pop up if Asy change to '3'
        jQuery('#Cell-container').select2('data',{id: 'TST', text: 'TST'}); 
         jQuery('#Priority').val(99); // not working for dropdown but works if change to input
         jQuery('#Asy').focus();
        }
         
    });
});

Post Reply