0

I am trying to create a custom form validation like in this tutorial. To do things the "clean" way, I tried to include my js file from my module but it doesn't seem to be working.

app\code\local\Jurgis\Validationenable\etc\config.xml

<?xml version="1.0"?>

<config>
    <modules>
        <Jurgis_Validationenable>
            <version>0.1.0</version>
        </Jurgis_Validationenable>
    </modules>
    <frontend>
        <layout>
                <Jurgis_Validationenable>
                    <file>layout.xml</file>
                </Jurgis_Validationenable>
        </layout>
    </frontend>
</config>

app\code\local\Jurgis\Validationenable\etc\layout.xml

<?xml version="1.0"?>
<layout version="0.1.0">
<default>
    <reference name="head">
        <action method="addJs"><script>Jurgis_Validation.js</script></action>
    </reference>
</default>
</layout>

it works if I straight up include it in app/design/frontend/base/default/layout/page.xml.

edit

It is still not working when I try to enable the layout through my module. My code: (The .js file is still in the same location)

app\code\local\Jurgis\Validationenable\etc\config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Jurgis_Validationenable>
            <version>0.1.0</version>
        </Jurgis_Validationenable>
    </modules>
    <global>
        <helpers>
            <Jurgis_Validationenable>
                <class>Jurgis_Validationenable_Helper</class>
            </Jurgis_Validationenable>
        </helpers>
    </global>
    <frontend>
        <layout>
            <updates>
                <Jurgis_Validationenable>
                    <file>Jurgis_Validationenable.xml</file>
                </Jurgis_Validationenable>
            </updates>
        </layout>
        <translate>
            <modules>
                <Jurgis_Validationenable>
                    <files>
                        <default>Jurgis_Validationenable.csv</default>
                    </files>
                </Jurgis_Validationenable>
            </modules>
        </translate>
    </frontend>
</config>

app\design\frontend\base\default\layout\Jurgis_Validationenable.xml

<?xml version="1.0"?>
<layout version="0.1.0">
    <default>
        <reference name="head">
            <action method="addJs"><script>Jurgis_Validation.js</script></action>
        </reference>
    </default>
</layout>

js\Jurgis_Validation.js

12
  • What is the location path of your .js file? Jul 19, 2017 at 8:15
  • added in the edit Jul 19, 2017 at 8:17
  • Can you check if your file is being included in your page source? Jul 19, 2017 at 8:20
  • your layout and js file name should be in small case only
    – Piyush
    Jul 19, 2017 at 8:23
  • 1
    Your code is correct. I have used the same in my local machine and everything is working as expected without any issues. Can you share your app/etc/modules/Jurgis_Validationenable.xml file? Jul 19, 2017 at 8:56

2 Answers 2

1

Like you say, you want to do things clean ! so:

app/code/local/Jurgis/Validationenable/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Jurgis_Validationenable>
            <version>0.1.0</version>
        </Jurgis_Validationenable>
    </modules>
    <global>
        <helpers>
            <jurgis_validationenable>
                <class>Jurgis_Validationenable_Helper</class>
            </jurgis_validationenable>
        </helpers>
    </global>
    <frontend>
        <layout>
            <updates>
                <jurgis_validationenable>
                    <file>jurgis_validationenable.xml</file>
                </jurgis_validationenable>
            </updates>
        </layout>
        <translate>
            <modules>
                <Jurgis_Validationenable>
                    <files>
                        <default>Jurgis_Validationenable.csv</default>
                    </files>
                </Jurgis_Validationenable>
            </modules>
        </translate>
    </frontend>
</config>

app/code/local/Jurgis/Validationenable/Helper/Data.php

<?php

class Jurgis_Validationenable_Helper_Data extends Mage_Core_Helper_Abstract{

}

app/design/frontend/{yourPackage}/{yourTheme}/layout/jurgis_validationenable.xml

<?xml version="1.0"?>
<layout version="0.1.0">
    <default>
        <reference name="head">
            <action method="addJs"><script>Jurgis_Validation.js</script></action>
        </reference>
    </default>
</layout>
5
  • Is the Helper and .csv file necessary entirely for translation purposes of the error message, or is there a different reason i'm not aware of? Jul 19, 2017 at 6:31
  • If you want to do your module properlly you should add them, the helper is for translations methods etc. .. the csv for translating your fields.
    – PЯINCƎ
    Jul 19, 2017 at 6:36
  • You're welcome. If that what you need, please accept the answer.
    – PЯINCƎ
    Jul 19, 2017 at 7:40
  • Sure, but I'm trying to get it working now, but something doesnt seem to work... I will post my code shortly. Jul 19, 2017 at 7:56
  • My bad, everything works! Jul 19, 2017 at 9:05
1

First of all, to add layout updates for frontend, your config.xml should look like this:

<config>
    ------------------
    <frontend>
        <layout>
            <updates>
                <add_an_unique_name>
                   <file>layout.xml</file>
                </add_an_unique_name>
            </updates>
        </layout>            
    </frontend>
</config>

Next, you should place layout.xml in your theme path under the layout folder: app/design/frontend/[package]/[theme]/layout/layout.xml. Also you could place it, for example, under the app/design/frontend/base/default/layout/ path, Magento will find it using the fallback system.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.