0

In my component's JTable's subclass, I have overridden the check() method to perform my internal checks, when saving an item with my JModelAdmin subclass.

So when saving an item, if any of those fails, my check() method returns false, and set to display a corresponding error message, using JFactory::getApplication()->enqueueMessage(JText::_('SOME_ERROR_OCCURRED'), 'error');

The problem is that every time there is an error on my JTable's check method, I get 2 displayed error messages. On top there is the one that I have enqueued, followed always by a second one:

Save failed with the following reason:

with no reason specified.

Why I am getting the second error message?

1 Answer 1

0

The problem is that the JModelAdmin save() method will display its own error messages. Regarding JTable's check method, it expects to return true or false from it, and accordingly either continue with its save execution, or return false and set an error message.

For the error message that will show, it will use JTable's getError() method: $table->getError() to retrieve the relative error message that should have been set in JTable.

So, the right way to display errors in JTable's check(), is to use:

if ($error)
{
    $this->setError(JText::_('SOME_ERROR_OCCURRED'));
    return false;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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