[Solved]Dynamic Fields on "New Ticket" - reset when hidden

Moderator: crythias

Locked
BlackRainbow
Znuny newbie
Posts: 2
Joined: 05 Jan 2015, 17:41
Znuny Version: 3.3.x

[Solved]Dynamic Fields on "New Ticket" - reset when hidden

Post by BlackRainbow »

Hi,

I'm currently working on some adjustments to my Customer Interface. OTRS version is 3.3.
With the help of the topics viewtopic.php?f=60&t=8032 and viewtopic.php?f=60&t=24116 I could solve most of my problems, so first of all thanks to everybody who posted there!

The last point on my to do list that is missing now, has to do with dynamic fields of the type "date".

The following code is working:

Code: Select all

    $('#DynamicField_Dyn1').bind('change', function (Event) {
switch ($('#DynamicField_Dyn1').val() ) {
case "yes":
	$('#DynamicField_Dyn1bText').parent().removeClass( 'Hidden' );
	$('#LabelDynamicField_Dyn1bText').parent().removeClass( 'Hidden' );
	$('#DynamicField_Dyn1bText').addClass( 'Validate_Required' );
	break;
case "no":
	$('#DynamicField_Dyn1bText').parent().addClass( 'Hidden' );
	$('#LabelDynamicField_Dyn1bText').parent().addClass( 'Hidden' );
	$('#DynamicField_Dyn1bText').removeClass( 'Validate_Required' );
	$('#DynamicField_Dyn1bText').val('');
	break;
default:
	break;
}
        Core.AJAX.FormUpdate($('#NewCustomerTicket'), 'AJAXUpdate', 'Dest', ['TypeID', 'PriorityID', 'ServiceID', 'SLAID', $Data{"DynamicFieldNamesStrg"}]);
    });
Dyn1bText is of type textarea. It appears, when Dyn1 is set to yes and it disappears when it is set back to no. Anything entered into the textarea is cleared when set back to no by "$('#DynamicField_Dyn1bText').val('');".

The following code is not working:

Code: Select all

    $('#DynamicField_Dyn2').bind('change', function (Event) {
switch ($('#DynamicField_Dyn2').val() ) {
case "yes":
	$("[id^=DynamicField_Dyn2bDate]").parent().removeClass( 'Hidden' );
	$("[id^=LabelDynamicFieldDyn2bDate]").parent().removeClass( 'Hidden' );
	$("[id^=DynamicField_Dyn2bDate]").addClass( 'Validate_Required' );
	break;
case "no":
	$("[id^=DynamicField]_Dyn2bDate").parent().addClass( 'Hidden' );
	$("[id^=LabelDynamicField_Dyn2bDate]").parent().addClass( 'Hidden' );
	$("[id^=DynamicField_Dyn2bDate").removeClass( 'Validate_Required' );
	$("[id^=DynamicField_Dyn2bDate").val('');
	break;
default:
	break;
}
        Core.AJAX.FormUpdate($('#NewCustomerTicket'), 'AJAXUpdate', 'Dest', ['TypeID', 'PriorityID', 'ServiceID', 'SLAID', $Data{"DynamicFieldNamesStrg"}]);
    });
Dyn2bDate is of type date. It appears and disappears as supposed to, but it is not reset properly.

I think it has to do with the type as this was also the reason why the "id^=" in the beginning of the lines was needed.

Could anybody give me some advice on how to set the date-field back to Null? (or uncheck the checkbox in front of the date)
I already tried with .val('false'), .val('uncheck'), .val('reset').

Thanks for reading. :)
Last edited by BlackRainbow on 13 Mar 2015, 15:47, edited 1 time in total.
Giulio Soleni
Znuny wizard
Posts: 392
Joined: 30 Dec 2010, 14:35
Znuny Version: 6.0.x and 5.0.x
Real Name: Giulio Soleni
Company: IKS srl

Re: Dynamic Fields on "New Ticket" - reset when hidden

Post by Giulio Soleni »

Hi,
as I specified here there are several id's to access the same date field.
So, if you named your field Dyn2bDate you will have:
DynamicField_Dyn2bDateUsed ... to make reference at the checkbox to select or not the dyn-field
DynamicField_Dyn2bDateMinute, DynamicField_Dyn2bDateHour, DynamicField_Dyn2bDateMonth, DynamicField_Dyn2bDateDay, DynamicField_Dyn2bDateYear for all the part of the dyn field.

If you need to reset the checkbox you should use this syntax:

Code: Select all

document.getElementById('DynamicField_Dyn2bDateUsed').checked = false;
instead of $("[id^=DynamicField_Dyn2bDate").val(''); which is wrong.

Different is the case if you want to "reset" the date dynamic field to the original value... honestly I would also like to have a way to reset the date to something null ... so that the user would be sure to set a correct date if he/she selects this field.
However the fields that compose a date attribute can be only filled up with valid digits, that is I should be able to (re)set for example:

Code: Select all

document.getElementById('DynamicField_Dyn2bDateYear').value = "2012";
but I cannot set for example:

Code: Select all

document.getElementById('DynamicField_Dyn2bDateYear').value = "";
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.
BlackRainbow
Znuny newbie
Posts: 2
Joined: 05 Jan 2015, 17:41
Znuny Version: 3.3.x

Re: Dynamic Fields on "New Ticket" - reset when hidden

Post by BlackRainbow »

Hi,

Thanks a lot for explaining it to me again. Seems like I skipped your post on the other thread... :(
Unchecking the checkbox is enough in my case. I just want to make sure that no date is written into the field, when the customer changes his mind switching back to "no".

It is working now, but I would like to add one thing as I had problems with the code not working at the beginning.
Looks like it is important where you put it exactly.

In my first example (with the textarea) I had the 'reset' at the end and it was working, but for the "date-case" it has to go before removing class 'Validate_Required'. At lease it wouldn't work for me, if it was behind it.

So the complete code then would be:

Code: Select all

    $('#DynamicField_Dyn2').bind('change', function (Event) {
switch ($('#DynamicField_Dyn2').val() ) {
case "yes":
   $("[id^=DynamicField_Dyn2bDate]").parent().removeClass( 'Hidden' );
   $("[id^=LabelDynamicFieldDyn2bDate]").parent().removeClass( 'Hidden' );
   $("[id^=DynamicField_Dyn2bDate]").addClass( 'Validate_Required' );
   break;
case "no":
   $("[id^=DynamicField_Dyn2bDate]").parent().addClass( 'Hidden' );
   $("[id^=LabelDynamicField_Dyn2bDate]").parent().addClass( 'Hidden' );
   get.ElementById('DynamicField_Dyn2bDate').checked = false;
   $("[id^=DynamicField_Dyn2bDate").removeClass( 'Validate_Required' );
   break;
default:
   break;
}
        Core.AJAX.FormUpdate($('#NewCustomerTicket'), 'AJAXUpdate', 'Dest', ['TypeID', 'PriorityID', 'ServiceID', 'SLAID', $Data{"DynamicFieldNamesStrg"}]);
    });
Thanks again and have a nice weekend! :)
Locked