Validation no longer functioning with Autofill and databasejoin

Ninpo

Member
Up until the updates done on May 13th, validation was functioning properly but now it seems that it is no longer working properly. I have tested this situation in MAMP and on a Linux sandbox and the problem exists in both places. All the testing I am doing is on the administrative side of the site.

I have a simple form that consists of 3 elements in addition to the standard elements brought in by the default template.

1. Employee: Database join linked to the Joomla Users table ID with the display set to name.
2. Employee Name: Read-only field
3. Employee Email: Read-only field. Validations are setup on this field for "areuniquevalues".

-- More fields will be added later when this is stabilized.

The objective is that when a user is creating a profile for a Joomla user, they select a user from a dropdown of users and the form autofills in the name and email address of the user from the Joomla users table. There can not be more than 1 profile per user so the uniqueness is key'ed from the email address.

The form has the autofill plugin enabled and mapped to auto populate the "Employee Name" and "Email Address". This is all working properly.

The problem is that if I try to add a second record for the same user, instead of the "areuniquevalues" validations being triggered and displaying an error on the same edit form, I get redirected to a rendered display-only view with no errors being displayed. This was working properly until I did an update from the Joomla3 branch of git yesterday.

When the rendered display view appears I get "autofill-min.js:2 Uncaught TypeError: Cannot read property 'get' of undefined" error within developer tools in chrome.
 
Yes. I have been doing quite a bit of testing lately with fabrik as I am getting ready to implement a large project with it for a client. So I have been tearing down sandboxes and rebuilding them quite a bit. With that, I have been getting the newest versions of Fabrik from git hub for every test iteration. The last test I did was prior to the 12th.
 
I have discovered that this issue has to do with list access control. You do not need to make such a complicated example to duplicate. Here is a simple way to reproduce the issue.

1. Create a Joomla User Group called "Nobody" with parent of public.
2. Create a Joomla View Access group called "Nobody" and assign it to the "Nobody" group.
3. Create a Fabrik list. I created one called "Test".
4. Set the List Access "Edit Records" to the new "Nobody" group.
5. Create an element for the new "Test" list and assign any validation to it as it really does not matter. For simplicity I created a validation for "areuniquevalues".
6. Add a record to the "Test" list and then try to trigger the validation rule by adding a second record duplicating the first. No error will be produced but you will get redirected back to a rendered "view" of the record as my original post.

If I set the List "edit" ACL to public the validation rule is successfully triggered. If List is set to the nobody group, I get no validation errors, just a rendered view.

So basically all this scenario does is disable editing privileges at the list level. Once this is done, validation does not work properly.
 
Last edited:
K, tx for the sleuthing. I'll look at it when I'm near a computer again.

Sent from my HTC One using Tapatalk
 
The reason why the "details" view is being displayed instead of the "form" view with the errors is because of line 313 in components/com_fabrik/views/form/view.base.php. For some reason "isEditable()" is returning false. Because of the logic in the ternary operator, "$view = $model->isEditable() === false ? 'details' : 'form';", The details view will always be returned if the user has no edit rights.

I slapped this into a debugger for a few minutes and put a watch in the model's editable property and saw that on line 137 in components/com_fabrik/controllers/form.php, "$this->handleError($view, $model);", the $model object shows that the editable is returning true and it's still true all the way to line 271 in the "handleError" function where it calls back to display the form "$view->display();".

The call on line 121 in components/com_fabrik/views/form/view.base.php "$model->render()" is where the editable property gets changed. Line 2895 in "components/com_fabrik/models/form.php" checks the ACL from the List object
$this->checkAccessFromListSettings();. on Line 504 editable is changed to false in that method because I have set the List to disallow editing by creating a pseudo ACL group that no one will belong to.

The code:

if (empty($data) || !array_key_exists('__pk_val', $data))
{
if ($listModel->canAdd()) { $ret = 3; }
else if ($listModel->canEdit($data)) { $ret = 2; }
} else
{
// Editing from - can we edit
if ($listModel->canEdit($data)) { $ret = 2; }
}
// If no access (0) or read only access (1) set the form to not be editable
$editable = ($ret <= 1) ? false : true;

It is returning 1 for false.

Since the $data object is not empty and the array key "__pk_val" does exist in the $data object, even though it is an empty string, the check for canAdd() is never looked at and it hits the else block. The only check in the else block is for canEdit() and the user does not have edit privileges.

Maybe use "is_null" instead of "array_key_exists" that way you can check for canAdd?

I hope this helps you.
 
Last edited:
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top