Jump to content

[SOLVED] Add javascript to module, extending form.tpl


PhpMadman

Recommended Posts

Hi.

 

I'm developing a module for 1.6, and later when it works, it will support 1.5 aswell.

I have managed to extend the helpers/form/form.tpl with my custom made one.

However, I added javascript to it, but it does work. My javascript dosen't even show up in the soruce code.

 

Here is my form.tpl (without the license)

Can anyone see what I'm missing?


{extends file="helpers/form/form.tpl"}

<script type="text/javascript">
{literal}
	function MoveProduct(src,destID)
	{
// 		var id = from.options[from.selectedIndex].value;
		var dest = document.getElementById(destID);
		
		for (var count=0; count < src.options.length; count++)
		{
			if (src.options[count].selected == true)
			{
				var option = src.options[count];
				var newOption = document.createElement('option');
				newOption.value = option.value;
				newOption.text = option.text;
				newOption.selected = true;
				try {
					dest.add(newOption, null); //Standard
					src.remove(count, null);
					alert('Standard');
				}catch(error) {
					dest.add(newOption); // IE only
					src.remove(count);
					alert('IE');
				}
				count--;
			}
		}
		return true;
	}
{/literal}
</script>

{block name="field"}
	{if $input.type == 'three_list'}
		{foreach $input.lists as $list}
			<div style="width:33%;float:left;text-align:center;">
				<label for="{$list.id}">{$list.label}</label>
				<select size="10"  id="{$list.id}">
					{foreach $list.selectlist as $option}
						<option value="{$option.id}">{foreach $list.option_syntax as $syntax}{$option[$syntax['key']]}{$syntax['seperator']}{/foreach}</option>
					{/foreach}
				</select>
				{foreach $list.move as $move}
					<button class="btn btn-default" name="Move" type="button" onclick="MoveProduct({$list.id},'{$move.to_id}');return false;">
						{if $move.direction == left}
							<i class="process-icon-back" style="display:inline;"></i>
							{$move.text}
						{else}
							{$move.text}
							<i class="process-icon-next" style="display:inline;"></i>
						{/if}
					</button>
				{/foreach}
			</div>
		{/foreach}
	{else}
		{$smarty.block.parent}
	{/if}
{/block}

Edited by PhpMadman (see edit history)
Link to comment
Share on other sites

Hi. I override the form for the configuration of my module.

{root}/modules/{module}/views/templates/admin/_configure/helpers/form/form.tpl

 

If you want to override a specific controller's form, you need to add it to that folder. Something along the lines of.

{root}/modules/{module}/views/templates/admin/{controller}/helpers/form/form.tpl

Link to comment
Share on other sites

I removed JS from tpl, and did this instead

	public function hookActionAdminControllerSetMedia($params)
	{
		// add necessary javascript to back office
		if($this->context->controller->controller_name == 'AdminModules' && Tools::getValue('configure') == $this->name
		&& Tools::getValue('tab_module') == 'administration' && Tools::getValue('module_name') == $this->name)
		{
			$this->context->controller->addJS($this->_path.'views/templates/_configure/helpers/form/form.js');
		}
	}

All of the if is requierd, beacuse the hook is executed on EVERY BO PAGE according to the forum posts I found.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...