Hide Dynamic Field at page load - Javascript Help

Moderator: crythias

Post Reply
pazt
OTRS newbie
Posts: 18
Joined: 06 Mar 2016, 21:06
OTRS Version?: 5.0.22
Real Name: Thiago Paz
Company: Landis+Gyr

Hide Dynamic Field at page load - Javascript Help

Post by pazt » 11 May 2016, 00:42

Hi,

I tested successfully this tutorial by crythias: viewtopic.php?t=24116.
The tutorial is to hide dynamic fields for specific Queue. And it work very well. But.... it's not exactly what i'm looking for.

I don't know anything about javascript. And i need some help.

That tutorial only works on Queue field change (switch). And I need hide or show dynamic fields at the page load. I mean.... when CustomerTicketMessage url is loaded, the javascript get the Queue value and hide the dynamic fields cited on javascript.

I tried if statement but unsuccessfully.

This i my current Queue script on CustomerTicketMessage.tt

Code: Select all

<script type="text/javascript">//<![CDATA[
function nonetext() {
	$("[id^=DynamicField]").parent().addClass( 'Hidden' );
 	$("[id^=LabelDynamicField]").parent().addClass('Hidden');
 }
 
 $('#Dest').bind('change', function (Event) {
 	Core.AJAX.FormUpdate($('#NewCustomerTicket'), 'AJAXUpdate', 'Dest', ['TypeID', 'PriorityID', 'ServiceID', 'SLAID', [% Data.DynamicFieldNamesStrg %]]);
 switch ( $('#Dest').val() ) {
 	case "5\|\|NOC": // need to slash escape the pipes. Also, need to be in numerical order
 	nonetext();
        $('#DynamicField_latitude').parent().removeClass( 'Hidden' );
        $('#LabelDynamicField_latitude').parent().removeClass( 'Hidden' );
        $('#DynamicField_longitude').parent().removeClass( 'Hidden' );
        $('#LabelDynamicField_longitude').parent().removeClass( 'Hidden' );
        break;
        default:
        nonetext();
}
});
//]]></script>
[% END %]
How can I do to run this javascript on page load?

Thanks
PazT

OTRS 5.0.22 | ITSM 5.0.22 | Ubuntu 16.04 LTS | MySQL 5.7

RStraub
OTRS guru
Posts: 2162
Joined: 13 Mar 2014, 09:16
OTRS Version?: 6.0.14
Real Name: Rolf Straub

Re: Hide Dynamic Field at page load - Javascript Help

Post by RStraub » 11 May 2016, 08:21

Your problem is that your function call to "nonetext()" is inside the event for a destination change.

Try moving it outside so that it is loaded once when the page has finished. For example, go to the very last block "WRAPPER JSOnDocumentComplete" you find, and add the function call there.
Currently using: OTRS 6.0.14 -- MariaDB -- Ubuntu 16 LTS

pazt
OTRS newbie
Posts: 18
Joined: 06 Mar 2016, 21:06
OTRS Version?: 5.0.22
Real Name: Thiago Paz
Company: Landis+Gyr

Re: Hide Dynamic Field at page load - Javascript Help

Post by pazt » 11 May 2016, 22:23

Thanks RStraub. It's works.

Just one more question.

First, all dynamic fields are load. The dynamic fields only are hidden when page has finished.

Is possible hide dynamic fields before CustomerTicketMessage.tt url be loaded?

Thanks again
PazT

OTRS 5.0.22 | ITSM 5.0.22 | Ubuntu 16.04 LTS | MySQL 5.7

RStraub
OTRS guru
Posts: 2162
Joined: 13 Mar 2014, 09:16
OTRS Version?: 6.0.14
Real Name: Rolf Straub

Re: Hide Dynamic Field at page load - Javascript Help

Post by RStraub » 12 May 2016, 15:42

Not that I know of. You could of course disable them in the config and try adding them via jquery (as long as the name is the same it should be passed to the next module).

But I haven't tried that.
Currently using: OTRS 6.0.14 -- MariaDB -- Ubuntu 16 LTS

Giulio Soleni
OTRS superhero
Posts: 391
Joined: 30 Dec 2010, 14:35
OTRS Version?: 6.0.x and 5.0.x
Real Name: Giulio Soleni
Company: IKS srl

Re: Hide Dynamic Field at page load - Javascript Help

Post by Giulio Soleni » 12 May 2016, 21:06

I have recently updated that howto and I enclosed my code within a

Code: Select all

$(document).ready(function() { ... });
that should play the trick ;)
OTRS 6.0.x on CentOS 7.x with MariaDB 10.2.x database connected to an Active Directory for Agents and Customers.
ITSM and FAQ modules installed.

Post Reply