J3 component tutorial problem

For Joomla! 3.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Locked
Tungsten15
Joomla! Apprentice
Joomla! Apprentice
Posts: 8
Joined: Thu Sep 18, 2014 11:29 am

J3 component tutorial problem

Post by Tungsten15 » Thu Sep 18, 2014 1:23 pm

Hi All,

I'm doing the Joomla 3 component tutorial up to where it is complete (trying to pick it up from 2.5) but I'm getting the following error:

Code: Select all

Uncaught TypeError: Cannot read property 'setHandler' of null 
The code looks like this:

Code: Select all

window.addEvent('domready', function() {
        document.formvalidator.setHandler('greeting',
                function (value) {
                        regex=/^[^0-9]+$/;
                        return regex.test(value);
        });
});
Any suggestion on how to fix it?

itoctopus
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 4025
Joined: Mon Nov 25, 2013 4:35 pm
Location: Montreal, Canada
Contact:

Re: J3 component tutorial problem

Post by itoctopus » Thu Sep 18, 2014 1:53 pm

You will need to install a jQuery plugin (there are many in the JED) since Joomla 2.5 does not include jQuery by default.
http://www.itoctopus.com - Joomla consulting at its finest
https://twitter.com/itoctopus - Follow us on Twitter

Tungsten15
Joomla! Apprentice
Joomla! Apprentice
Posts: 8
Joined: Thu Sep 18, 2014 11:29 am

Re: J3 component tutorial problem

Post by Tungsten15 » Thu Sep 18, 2014 3:06 pm

Thank you for the response, I will try your suggestion. I was under the impression that Joomla 3 came with JQUery?

Tungsten15
Joomla! Apprentice
Joomla! Apprentice
Posts: 8
Joined: Thu Sep 18, 2014 11:29 am

Re: J3 component tutorial problem

Post by Tungsten15 » Thu Sep 18, 2014 4:19 pm

I installed eorisis' JQuery plugin - I didn't fix the problem

sovainfo
Joomla! Exemplar
Joomla! Exemplar
Posts: 8808
Joined: Sat Oct 01, 2011 7:06 pm

Re: J3 component tutorial problem

Post by sovainfo » Thu Sep 18, 2014 6:55 pm

No surprise there! Proposed as a fix for J2.5, not J3!

Also the code looks like normal javascript, not using JQuery. Looks like it requires Mootools. Is it loaded?
Issue with migrating? Include logs/joomla_update.php in your report!
Blank screen? Verify pagesource for HTML code (javascript error)
Installation failing on populating database? Install with set_time_limit(0)
Document your customizations!

Tungsten15
Joomla! Apprentice
Joomla! Apprentice
Posts: 8
Joined: Thu Sep 18, 2014 11:29 am

Re: J3 component tutorial problem

Post by Tungsten15 » Fri Sep 19, 2014 6:33 am

Why do I need Mootools? It didn't suggest it in the tutorial.

sovainfo
Joomla! Exemplar
Joomla! Exemplar
Posts: 8808
Joined: Sat Oct 01, 2011 7:06 pm

Re: J3 component tutorial problem

Post by sovainfo » Fri Sep 19, 2014 8:02 am

Because validator is a class provided by mootools. Mootools is standard available in J2.5. In J3 it needs to be loaded when required. The message says it can't find setHandler in null which means document.validator doesn't resolve to an object.
Issue with migrating? Include logs/joomla_update.php in your report!
Blank screen? Verify pagesource for HTML code (javascript error)
Installation failing on populating database? Install with set_time_limit(0)
Document your customizations!

Tungsten15
Joomla! Apprentice
Joomla! Apprentice
Posts: 8
Joined: Thu Sep 18, 2014 11:29 am

Re: J3 component tutorial problem

Post by Tungsten15 » Fri Sep 19, 2014 8:37 am

But I have:

Code: Select all

JHtml::_('behavior.formvalidation');
I've also enabled Mootools using this suggestion

Code: Select all

JHtml::_('behavior.framework', true);
But it is not working :(

sovainfo
Joomla! Exemplar
Joomla! Exemplar
Posts: 8808
Joined: Sat Oct 01, 2011 7:06 pm

Re: J3 component tutorial problem

Post by sovainfo » Fri Sep 19, 2014 3:05 pm

Any javascript errors when loading the page to see with Firebug?
Issue with migrating? Include logs/joomla_update.php in your report!
Blank screen? Verify pagesource for HTML code (javascript error)
Installation failing on populating database? Install with set_time_limit(0)
Document your customizations!

Tungsten15
Joomla! Apprentice
Joomla! Apprentice
Posts: 8
Joined: Thu Sep 18, 2014 11:29 am

Re: J3 component tutorial problem

Post by Tungsten15 » Mon Sep 22, 2014 8:52 am

Using Chrome:

Code: Select all

Failed to load resource: net::ERR_CACHE_MISS
Uncaught TypeError: Cannot read property 'setHandler' of null 
Uncaught TypeError: Cannot read property 'task' of null

bbolli
Joomla! Explorer
Joomla! Explorer
Posts: 455
Joined: Fri Nov 11, 2011 9:43 pm
Location: Chicago, IL

Re: J3 component tutorial problem

Post by bbolli » Wed Sep 24, 2014 12:43 am

Did you add the validate-greeting class to your form field definition xml file for the field you're trying to validate?

akfaisel
Joomla! Apprentice
Joomla! Apprentice
Posts: 29
Joined: Mon Jul 12, 2010 1:12 pm

Re: J3 component tutorial problem

Post by akfaisel » Sat Nov 01, 2014 2:58 am

Hi,

Try the following code.

Code: Select all

jQuery(function() {
        document.formvalidator.setHandler('greeting',
                function (value) {
                        regex=/^[^0-9]+$/;
                        return regex.test(value);
        });
});
The reason for the error is, starting from J3, validate.js is using jQuery for form validation.
Thank You
Regards
Faisel


Locked

Return to “Joomla! 3.x Coding”