Trying to create a custom validation rule in frontend, always get the same error:
0 Joomla\CMS\Form\Field\TextField::validate() rule
Espaciocheck
missing.
Please, will the path to the file be wrong? What could be missing?
com_aaprueba/forms/espacio.xml
<?xml version="1.0" encoding="utf-8"?>
<form addfieldprefix="Sfi\Component\Aaprueba\Site\Field">
<fieldset addruleprefix="Sfi\Aaprueba\Site\Rule">
<field
name="espacio"
type="text"
label="COM_AAPRUEBA_FIELD_ESPACIO"
description="COM_AAPRUEBA_FIELD_ESPACIO_DESC"
required="true"
validate="Espaciocheck"
/>
...
com_aaprueba/tmpl/espacio/default.php
...
<form action="<?= Route::_('index.php?option=com_aaprueba&view=espacio&id='.(int) $this->item->id); ?>" method="post" name="adminForm" id="adminForm" class="form-validate">
...
<?= $this->form->renderField('espacio'); ?>
...
com_aaprueba/src/View/Espacio/HtmlView.php
namespace Sfi\Component\Aaprueba\Site\View\Espacio;
...
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\HTML\Helpers\Behavior;
use Joomla\CMS\Form\FormHelper;
...
class HtmlView extends BaseHtmlView
{
...
public function display($tpl = null)
{
Behavior::formvalidator();
...
com_aaprueba/src/Rule/EspaciocheckRule.php
namespace Sfi\Component\Aaprueba\Site\Rule;
\defined('_JEXEC') or die;
use Joomla\CMS\Form\FormRule;
class EspaciocheckRule extends FormRule
{
public function test(\SimpleXMLElement $element, $value, $group = null, Registry $input = null, Form $form = null)
{
// Logic after working test
return true;
}
}
addruleprefix
attribute.