Hi,
can somebody paste some example to this:
Joomla 3:
Joomla 4
This triggers: Joomla\CMS\Form\Field\EmailField::validate() rule customemailrule
missing in libraries/src/Form/Form.php (1236)
What is the right way to implement custom rules in Joomla 4? (in comparison to J3)
Thank you.
EDIT:
Possible problem can be in libraries/src/Form/FormHelper.php
where loadClass method sets wrong path:
Joomla\CMS\Form\Rule\CustomEmailRule
istead of
components/com_custom/models/rules/customemail.php
even the XML Form defined it:
<fieldset addfieldpath="/components/com_custom/models/fields" addrulepath="/components/com_custom/models/rules">
Labels |
Added:
No Code Attached Yet
|
Hi, I am testing Joomla 3 component, so it works in Joomla 3 (this is not new component), so things like
validate="" attribute is customemail and not CustomEmail
are OK there.
It just does not load the class in this file:
components/com_custom/models/rules/customemail.php
BTW the field is core field:
<field name="email" type="email" ... validate="customemail" filter="string" />
only rule is custom rule from the custom component.
Jan
Hmmm, the behaviour is completely different and broke the current working feature :-(
Do you mind attach a copy of your current code and tell us what we need to do to see the error? That would help us to see the error and try to figure out what's wrong.
I cannot reproduce, I tried with mod_custom:
Create a field <field type="text" name="test" label="test" validate="customemail"/>
;
Add addrulepath="/modules/mod_custom/rules"
to fieldset;
Create a rule: modules/mod_custom/rules/customemail.php
;
with:
class JFormRuleCustomemail
{
public function test(\SimpleXMLElement $element, $value)
{
return false;
}
}
On save I got "invalid field: Test", as expected.
Do you get the same with type="email" and class JFormRuleCustomEmail extends EmailRule?
Hi @Fedik , thank you for your comments, based on this I have found the problem. When using legacy MVC structure, this is not valid: FormRuleCustomEmail extends EmailRule, but this is valid: JFormRuleCustomEmail extends EmailRule
So this seems to be solved, I will do some more tests on different rules, but I hope, this was the reason for the issue.
Thank you, Jan
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2021-10-29 19:10:30 |
Closed_By | ⇒ | PhocaCz |
old way still should work, make sure
validate=""
attribute iscustomemail
and notCustomEmail
it basically create a
validate()
method inside your field. This is default:joomla-cms/libraries/src/Form/FormField.php
Lines 1183 to 1198 in 81db97d