Page 3 of 4

Re: Conditional Dropdown Boxes

Posted: Mon Jul 02, 2012 6:51 am
by dr_patso
I think the reason the text isn't aligned is because the text TD for the custom field already has a style of "text-align:right" (i defined this line as sntext) not sure how to change the style to that with javascript....

I tried text-align:right , I tried "right" I tried changing

Code: Select all

{document.getElementById('custom1').style.display = 'none';} 
to

Code: Select all

{document.getElementById('custom1').style.textAlign= 'right';} 
no success so far..

might also be because it is actually the 2nd field defining the width, which had no style so I would think BLOCK would bring it back in place how it needs to be for alignment.... until I set this field to display none it would knock my other custom fields out of alignment.....






ya so you'd have to apply something like this in the java function to all category ids you don't want to display the custom field.

Code: Select all

	if (document.getElementById('category').value == '2') {document.getElementById('sntext').style.display = 'none';}
	if (document.getElementById('category').value == '2') {document.getElementById('space1').style.display = 'none';} 
	if (document.getElementById('category').value == '2') {document.getElementById('custom1').style.display = 'none';} 

Re: Conditional Dropdown Boxes

Posted: Mon Jul 02, 2012 8:11 am
by dr_patso
crap I don't think you can do a text-alight: right with javascript.. I think I will have to wrap the custom field in a div class....

another day of work probably...

Re: Conditional Dropdown Boxes

Posted: Mon Jul 02, 2012 8:35 am
by dr_patso
So I hid my required field with the style display: none.. as I expected as I really started thinking about it, when the required custom field was missing from the thew admin/new_ticket page it errored that I need to input timespent, but not possible to pull off.

In this situation I would need some kind of code that put a value such as "N/A" when the field was hidden..

Re: Conditional Dropdown Boxes

Posted: Mon Jul 02, 2012 11:02 pm
by dr_patso
i'm currently stuck on this issue, will post update if solved


javascript

Code: Select all

	<script language="javascript" type="text/javascript">
	function test() {
    if (document.getElementById('category').value == '1') {document.getElementById('custom1').style.display = 'block';} 
	if (document.getElementById('category').value == '1') {document.getElementById('sntext').style.display= 'block';} 
	if (document.getElementById('category').value == '2') {document.getElementById('sntext').style.display = 'none';}
	if (document.getElementById('category').value == '2') {document.getElementById('custom1').style.display = 'none';} 
	}

	</script>
the category field

Code: Select all

<td width="80%"><select id="category" name="category" onchange='test()' <?php if (in_array('category',$_SESSION['iserror'])) {echo ' class="isError" ';} elseif (in_array('category',$_SESSION['isnotice'])) {echo ' class="isNotice" ';} ?> >
	<option value="">-- Please select --</option>
the field i am hiding

Code: Select all

	<tr>
	<td style="display: none; text-align: right; " id="sntext" width="150"><?php echo $hesklang['serialn']; ?>:</td>
	<td width="80%" id="custom1" style="display: none"><input type="text" name="custom1" size="40" maxlength="25" value="<?php if (isset($_SESSION['as_custom1'])) {echo stripslashes(hesk_input($_SESSION['as_custom1']));} ?>"Autocomplete="off"/></td>
	</tr>
This works perfectly in IE, in firefox and chrome its like the text field box gets a return and screws up the layout

internet explorer
Image

firefox
Image

Re: Conditional Dropdown Boxes

Posted: Tue Jul 03, 2012 2:44 pm
by plc
Perhaps we should consider taking a "big picture" stance and integrating all features namely:

1 - making use of Hesk categories
2 - hiding/showing only relevant sub-cats
3 - hiding/showing only relevant third(forth, fifth...etc) tier sub-cats
4 - populating data from database

For the latter, I found a code *I think* we can work from here[1].

References:
[1]http://forums.digitalpoint.com/showthread.php?t=703846

Re: Conditional Dropdown Boxes

Posted: Tue Jul 03, 2012 6:51 pm
by dr_patso
good find plc! maybe I'll play with that..


it pisses me off that i am so close, stupid cross browser support.. I was reading Jquery although overkill for this task has better cross browser support so maybe i'll try that too in the future.

I don't mind fields showing that are unneccessary in the admin ticket .. so just editing the form is good enough for me.... I'm curios if hesk 2.4 has any extra features for custom fields and maybe I am wasting my time.

Re: Conditional Dropdown Boxes

Posted: Tue Jul 03, 2012 7:57 pm
by dr_patso
i got it to work with setting the displays to "" - nothing.. so instead of display: none. there just is no style.. im guessing block adds a type of style that makes firefox return the line, and not IE... this way it works in both IE AND firefox

Code: Select all

	<script language="javascript" type="text/javascript">
	function test() {
    if (document.getElementById('category').value == '1') {document.getElementById('custom1').style.display = '';} 
	if (document.getElementById('category').value == '1') {document.getElementById('sntext').style.display= '';} 
	if (document.getElementById('category').value == '2') {document.getElementById('sntext').style.display = 'none';}
	if (document.getElementById('category').value == '2') {document.getElementById('custom1').style.display = 'none';} 
	}


ofcourse you'd have to do this for EVERY single category ID.. but HEY.. it works... now I need to find a way to input data in required fields upon hiding them for this to work with my "required" custom fields

Re: Conditional Dropdown Boxes

Posted: Wed Jul 04, 2012 12:03 am
by steve
Wow dr patso, you have been busy!

I have too, that's why I haven't been active on this topic for a few days.

Instead of trying to input data into the "hidden" fields (which adds unnecessary data to your database) make the Required field conditional.

Open admin/admin_submit_tickets.php

find the code that checks for data in the required filed (around line 50)

Code: Select all

$tmpvar['custom1'] = hesk_input($_POST['custom1']) or $hesk_error_buffer['custom1']="Please enter Something";
Then change it to

Code: Select all

if ($tmpvar['category']== '1')
{$tmpvar['custom1'] = hesk_input($_POST['custom1']) or $hesk_error_buffer['custom1']="Please enter Something";}
So the logic is as follows:

IF the category = 1 then custom1 is required, other wise it is not required.

I guess next we have to add a tab on the settings page to allow us to change the sub category values without having to edit the source code :shock:

Re: Conditional Dropdown Boxes

Posted: Wed Jul 04, 2012 3:57 am
by dr_patso
NICE!

I thought it would be cool to remove and unrequire the subject and message field for certain menial tasks that must be logged.

I'm really interested in your javascript to update a field before user can mark resolved.. but I probably should wait until Hesk 2.4 since it has a whole timespent thing, that's the only thing i want to make sure myself and other users update before resolution... i find myself spending extra time on tickets and forgetting to update the timespent field constantly.

I'm assuming since conditional logic is not applied to the submit ticket form in 2.4 our efforts here will work on hesk 2.4 and be worth the time...

Re: Conditional Dropdown Boxes

Posted: Wed Jul 04, 2012 4:05 am
by steve
What I have done for subject and message fields is, well I actually removed the subject field entirely, then for the message field (which I use as a reported issue field), ADMIN's are allowed to leave it blank, while users are required to input data.

Its really basic Javascript for the popup box actually, the part that is a little tricky is taking the data acquired from the user and inputting that into the database. Like I said before, I'm going to wait till 2.4 to work on this one even though I'm pretty sure the code would work on either version.

Re: Conditional Dropdown Boxes

Posted: Wed Jul 04, 2012 11:02 pm
by steve
dr_patso wrote:i'm currently stuck on this issue, will post update if solved


javascript

Code: Select all

	<script language="javascript" type="text/javascript">
	function test() {
    if (document.getElementById('category').value == '1') {document.getElementById('custom1').style.display = 'block';} 
	if (document.getElementById('category').value == '1') {document.getElementById('sntext').style.display= 'block';} 
	if (document.getElementById('category').value == '2') {document.getElementById('sntext').style.display = 'none';}
	if (document.getElementById('category').value == '2') {document.getElementById('custom1').style.display = 'none';} 
	}

	</script>
the category field

Code: Select all

<td width="80%"><select id="category" name="category" onchange='test()' <?php if (in_array('category',$_SESSION['iserror'])) {echo ' class="isError" ';} elseif (in_array('category',$_SESSION['isnotice'])) {echo ' class="isNotice" ';} ?> >
	<option value="">-- Please select --</option>
the field i am hiding

Code: Select all

	<tr>
	<td style="display: none; text-align: right; " id="sntext" width="150"><?php echo $hesklang['serialn']; ?>:</td>
	<td width="80%" id="custom1" style="display: none"><input type="text" name="custom1" size="40" maxlength="25" value="<?php if (isset($_SESSION['as_custom1'])) {echo stripslashes(hesk_input($_SESSION['as_custom1']));} ?>"Autocomplete="off"/></td>
	</tr>
This works perfectly in IE, in firefox and chrome its like the text field box gets a return and screws up the layout

internet explorer
Image

firefox
Image
Were you every able to get this working?

Using the code you posted, I cant seem to make this work, or maybe I have misunderstood its functionality.

As I understand it, When category 1 is selected the defined custom field and its label are hidden, if category 2 is selected the previously hidden field is now shown. Does that sound about right?

The mod is spread across several posts, maybe you could post the whole mod in one post for me and other interested users?

Re: Conditional Dropdown Boxes

Posted: Thu Jul 05, 2012 5:45 pm
by dr_patso
The javascript is wrong if you are having a display issue


i posteed after that my new java

Code: Select all

<script language="javascript" type="text/javascript">
   function test() {
    if (document.getElementById('category').value == '1') {document.getElementById('custom1').style.display = '';}
   if (document.getElementById('category').value == '1') {document.getElementById('sntext').style.display= '';}
   if (document.getElementById('category').value == '2') {document.getElementById('sntext').style.display = 'none';}
   if (document.getElementById('category').value == '2') {document.getElementById('custom1').style.display = 'none';}
   }

you have to give an ID to the <td> you are hiding.. inside the {} instead of setting display to 'block' setting it to '' (blank, no style at all) basically, if category 1 is selected then my <td> line with id sntext and my <td> line with custom1 as the ID get their style changed from "display: none" to nothing and or blank..


if category 2 is selected then that custom field dissapears... I would need to have every category ID I have that doesn't need that field to be setting it to display none so when i get off of the category set to display the field it dissapears...... unless i could trust everyone to only click once on the cateogry they needed and never change it...

I'm still trying to come up with all my custom fields before I start implementing it fully on the test server.

Re: Conditional Dropdown Boxes

Posted: Wed Jul 18, 2012 2:58 pm
by plc
Any progress guys? Just curious....

Re: Conditional Dropdown Boxes

Posted: Wed Jul 18, 2012 4:41 pm
by steve
I have not even look at this since my last post. I have been so busy. Ill get back to this when I have some time, ill post any results.

Re: Conditional Dropdown Boxes

Posted: Wed Jul 18, 2012 6:07 pm
by plc
No worries. Just checking. Thanks!