Custom Client Side Validation Fail

601 views
Skip to first unread message

Viktor Iwan

unread,
May 28, 2012, 10:20:18 AM5/28/12
to Joomla! General Development
Hello,
i need to create client side validation, i'm taking the reference
here:
http://docs.joomla.org/Client-side_form_validation

my problem is i couldn't make form validation works because of missing
rule.

Here's my setting:
xml setting for form:
<field name="testfield"
type="text"
label="COM_BENGKEL_TESTFIELD_LABEL"
description="COM_BENGKEL_TESTFIELD_DESC"
class="inputbox validate-testval"
validate="testval"
size="45" />

in edit.php (view) i add this line:

Window.onDomReady(function(){
document.formvalidator.setHandler('testval', function (value) {
return (value!=123);
});
});

The Result when i try to submit form:
"Validation Rule missing: testval"

Anybody can help me where did i go wrong ? there's no problem with
validate-email, etc

Thanks

piotr_cz

unread,
May 29, 2012, 5:46:33 AM5/29/12
to Joomla! General Development
Did you try using field attribute class="validate-testval"?

The 'validate' field attribute is probably for server-side validation
that utilizes JRule package. You are seeing this option because you
didn't define rule 'testval' for your form.
To do so, check out how com_contacts use it: /components/com_contacts/
models/forms/contact.xml and models/rules folder

Documentation page is for Joomla 1.5

BTW, use `window.addEvent('domready', function {` in the javascript
code. This is Mootools cross-browser wrapper for onDomReady event.

Viktor Iwan

unread,
May 30, 2012, 3:32:05 AM5/30/12
to Joomla! General Development
Hello,
Thanks, now i understand more about validate param in XML, is there
any tutorial about this...

Ok, Regarding Client side validation, i change my javascript to this:
window.addEvent('domready', function() {
document.formvalidator.setHandler('testval',
function (value) {
alert('test');
return (value==123);
});
});


and XML to this:
<field name="testfield"
type="text"
label="COM_BENGKEL_TESTFIELD_LABEL"
description="COM_BENGKEL_TESTFIELD_DESC"
class="inputbox validate-testval"
validate="testval"
size="45" />

the problem still exist, it can submit form even the value is not
'123', does client side validation works on submit ?

Viktor Iwan

unread,
May 30, 2012, 3:39:21 AM5/30/12
to Joomla! General Development
sorry i mean
<field name="testfield"
type="text"
label="COM_BENGKEL_TESTFIELD_LABEL"
description="COM_BENGKEL_TESTFIELD_DESC"
class="inputbox validate-testval"
size="45" />

Viktor Iwan

unread,
May 30, 2012, 5:17:11 AM5/30/12
to Joomla! General Development
I solved it.. it seem i miss some curly branches (syntax error)...
Thanks for your help

Dalton

unread,
May 30, 2012, 10:54:47 PM5/30/12
to joomla-de...@googlegroups.com
Pada Rabu, 30 Mei 2012 14:32:05 UTC+7, Viktor Iwan menulis:
Hello, 
Thanks, now i understand more about validate param in XML, is there 
any tutorial about this... 


salam
dani
  

piotr_cz

unread,
May 31, 2012, 3:31:50 AM5/31/12
to Joomla! General Development
In case that client-side validation fails (javascript disabled/ error
in code/ form submitted not from a browser), the server-side
validation should evaluate faulty field and instead of processing the
form return to form edit page.

Unfortunately, there seems to be no tutorial on form validation yet,
except the one you found which is for Joomla 1.5.
I wish JForm creators would add some, this is extremely useful but
complex package.

elin

unread,
May 31, 2012, 9:39:58 PM5/31/12
to joomla-de...@googlegroups.com
In my experience  the fact is for actual documentation that's useful for people who don't understand it already ... the creators are not really ideal authors. People who have worked their way through practical usage  without a lot of assumptions will be better.


Elin
Reply all
Reply to author
Forward
0 new messages