Jump to content

Remove option to upload attachment for a specific department


Tom Wilson

Recommended Posts

There are probably better ways and I'm not that good with jQuery but this is how I would do it. Depending on the selected department the script hides/shows attachments section. It also clears any existing attachment when vistors switch department. I tested it on Six template. Use it as a starting point since as I already said my jQuery skills are... 🤢

<?php

add_hook('ClientAreaHeadOutput', 1, function($vars)
{
	$deptID = '1'; // Hide Attachment for the given Department ID

	return <<<HTML
<script>
$(document).ready(function() {
	if ($('select#inputDepartment').val() == '{$deptID}') toggleAttachments('show'); else toggleAttachments('hide');

	$('#inputDepartment').on('change', function() {
    	if ($('select#inputDepartment').val() == '{$deptID}') toggleAttachments('show'); else toggleAttachments('hide');
    });
});

function toggleAttachments(e) {

	if (e == 'hide') {
		$('#inputAttachments').closest('.form-group').hide();
		$('#inputAttachments').val(''); 
	}

	if (e == 'show') {
		$('#inputAttachments').closest('.form-group').show();
	}
}
</script>
HTML;
});

 

Edited by Kian
Link to comment
Share on other sites

12 hours ago, Kian said:

There are probably better ways and I'm not that good with jQuery but this is how I would do it.

if the templates used IDs correctly (or even at all), then CSS would be simpler... but with that flaw to contend with, you're hooking - and I suspect it would have to be JS because the page doesn't refresh on a department change, so Smarty solutions would be limited.

12 hours ago, Kian said:

Depending on the selected department the script hides/shows attachments section. It also clears any existing attachment when visitors switch department. I tested it on Six template.

I think it shows the attachments for the specified depts, but hides it for others (e.g the reverse of what you want) - it also seems to hide the custom fields too...

12 hours ago, Kian said:

Use it as a starting point since as I already said my jQuery skills are...

they won't be as bad as mine! 🙄

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated