Hexagon Geospatial
MENU

GeoMedia Smart Client

GeoMedia Smart Client community discussion board is where you can create, contribute and share information and knowledge in regards to configuring as well as working with GeoMedia Smart Client. Find your answers, share your knowledge and help build a strong GeoMedia Smart Client community.
Showing results for 
Search instead for 
Do you mean 
Reply
Contributor
Posts: 66
Registered: ‎05-02-2016
Accepted Solution

Javascript - Clearing Fields if Tab is hidden

Hi, I have a form where there are three checkboxes on the first tab, each one activating/making visible one of the other three tabs.

If the user has activated and populated fields in one of the other tabs, and realise that tab isn't required they can untick the checkbox in the first tab to hide it again.

 

I want the fields in that now hidden tab to be cleared but I am trying to figure out a way to do this.

 

The Javascript to make the tab visible/hidden based on the checkbox is

 

//Execute  function on load. The variables are the checkbox and tab name
TabVisible('#Weeding_Activities_Check', 'Activities_Tab');
TabVisible('#Reveg_Activities_Check', 'Reveg_Tab');
TabVisible('#Other_Activities_Check', 'Other_Tab');
	
//Execute function on change
$("#Weeding_Activities_Check").change(function() {
	TabVisible('#Weeding_Activities_Check', 'Activities_Tab');		
   	});
	
$("#Reveg_Activities_Check").change(function() {
	TabVisible('#Reveg_Activities_Check', 'Reveg_Tab');
    	});
	
$("#Other_Activities_Check").change(function() {
        TabVisible('#Other_Activities_Check', 'Other_Tab');
    	});
	
//actual function function TabVisible(Val1, Val2) { if ($(Val1).is(':checked')) { IG._form.getItemById(Val2).visible(true); } else { IG._form.getItemById(Val2).visible(false); }; };

I have looked through the Smart Client site as well as online and can't figure a way of getting the field names within a tab. I imagine I would either loop through the three tabs for field names to hide, or just incorporate it into my if statement. Any ideas?

 

 

Thanks,

 

Josh

Staff
Posts: 1,036
Registered: ‎10-18-2015

Re: Javascript - Clearing Fields if Tab is hidden

Hi Josh,

 

it should be enough to use the hide() method:

 

IG.getItemById('Val2').hide();

 

or show()

 

IG.getItemById('Val2').show();

 

The list of available methods is available here. I think this documentation is going to be moved to the fluidtopics official one.

 

Thanks,

Stefano

 

 

Stefano Turcato
Presale Engineer
Hexagon Geospatial
Contributor
Posts: 66
Registered: ‎05-02-2016

Re: Javascript - Clearing Fields if Tab is hidden

Hi Stefano,

 

This hides the tab, but I want it to clear the fields within that tab also.

How does one loop/iterate through fields within a tab?

 

Regards,

 

Josh

Highlighted
Frequent Contributor
Posts: 77
Registered: ‎10-12-2015

Re: Javascript - Clearing Fields if Tab is hidden

[ Edited ]

Hi Josh,

 

Try this in your function:

 

function TabVisible(Val1, Val2) {					
	if ($(Val1).is(':checked')) {	
		IG._form.getItemById(Val2).visible(true);
	} else {																		
		IG._form.getItemById(Val2).visible(false);
		for (i=0;i<IG.form.getFields().length;i++) {if(IG.getItemById(IG.form.getFields()[i].parentId()).parentId()==Val2) {IG.form.getFields()[i].clear()}}
		};																				
	};

It loops through all the fields inside the form and checks if it's in the tab you're hiding to clear it.

I did not find a way to only loop through the fields in a tab.

 

Hope this helps.

 

Regards,

Radu

Contributor
Posts: 66
Registered: ‎05-02-2016

Re: Javascript - Clearing Fields if Tab is hidden

Thanks Radu,

 

It works.

I just made a couple of adjustments to include fields in formsinglerows and I can't clear comboboxes and checkboxes with .clear()

 

function TabVisible(Val1, Val2) {
if ($(Val1).is(':checked')) {
  IG._form.getItemById(Val2).visible(true);
} else {
  IG._form.getItemById(Val2).visible(false);
    for (i=0;i<IG.form.getFields().length;i++) {
	  if(IG.getItemById(IG.form.getFields()[i].parentId()).parentId()==Val2) {
		IG.form.getItemById(IG.form.getFields()[i].id).setValue('');
		  } else if (IG.getItemById(IG.getItemById(IG.form.getFields()[i].parentId()).parentId()).parentId()==Val2) {
			IG.form.getItemById(IG.form.getFields()[i].id).setValue('');
		  };
		};
	};
};
Do you need immediate support?
If you encounter a critical issue and need immediate assistance please submit a Service Request through our Support Portal.