Bug: New Tag element entries lost after validation error

VOI

Member
Hi,

I really like the new tag element plugin - and would like to use it on my site.

However, during tests I realized that new entries are gone when trying to save the from in case any validation error in another element occurs. Tag entries from a previous successful save are still there, though.

Since I am using the bootstrap_tab template the user probably will not realize that his previously entered new tag entry is lost.

I hope this is a bug and not a feature ;-)

Chris
 
Update from Github today. Still any new tags get lost after a failed validation. However, there is an empty tag shown in the tags field - s. attached screenshot (the tag "Remscheid" had been saved before the validation error occured)

Moreover, tags elements - and probably other repeatable elements as well - seem to cause an PHP error in any PHP form plugin not run "onAfterProcess": I have a form with a PHP form plugin set to run onLoad and a tag element calles "tag". Whenever a validation fails on this form, I get the following PHP error (error reporting set to maximum in Global Settings):

Code:
Notice: Undefined index: table___tag in /components/com_fabrik/models/plugin-form.php on line 323

The array where table__tag is missing is '$model->formDataWithTableName'. When displaying its content using J!Dump its obvious that it only contains a few elements from the form. If I set the PHP form plugin to run "onAfterProcess" the array is complete and the PHP error is not shown.

Could you maybe have another look at this one?

Thanks.

Chris
 

Attachments

  • tags.png
    tags.png
    2.2 KB · Views: 267
I think I've fixed the warning, but probably not made any difference to the "disappearing tags" issue. Let me know.

-- hugh
 
Thanks for finxing the warning.

Regarding the disapperaing issue I did some more research using J!Dump. The $data object is filled corretly after a validation error thanks to your last commit.

However, in 2 out of 3 possible entry types in the tag element the line 87 in the tags element plugin file 'tags.php'.

Code:
$tmp = $this->_getOptions($data, $repeatCounter, true);

does not return all tags in the correct format after a validaiton error.

The 3 entry types being:
  1. a new entry using a tag which already exists in jos_tags and in the table created for the tag element, e.g. table_repeat_tag
  2. a new entry using a tag which already exists in jos_tags, but NOT in table_repeat_tag
  3. a new entry which neither exits in jos_tags nor in table_repeat_tag
In case 1 everything works fine after a validation error - all tags entered before are shown.

In case 2 and 3 the new entry is not part of $tmp and therefore not displayed. IMHO, reason for this is the way the function _getOptions respectivley _getOptionsVals translates $data into text and value. The crucial line of code seems to be line 559 in the databasejoin element plugin file 'databasejoin.php':

Code:
$this->optionVals[$sqlKey] = $db->loadObjectList();

In case 2 '$sqlKey' would be:

Code:
SELECT DISTINCT(t.id) AS value,`title` AS text
FROM `table_repeat_tag` AS `table_repeat_tag`
LEFT JOIN #__tags AS t ON t.id = `table_repeat_tag`.`tag`
WHERE `table_repeat_tag`.`tag` IN (0)

The part causing the problem is the 0 in the WHERE clause - 0 since there is no entry in jos_tags for the new entry.

In case 3 instead of the 0 the SQL query would contain the ID of the tag in jos_tags, but the SQL query would return null since no record in table_repeat_tag has this value in the column 'tag' yet.

So for case 2 and 3 we probably need another way of returning the text and value for new entries instead of using '_getOptoins'.

Maybe we could use 'this->getValue' to check if there are any entries in the tag element belonging to case 2 or 3. Case 2 could be then solved by just stripping the prefix '#fabrik#' from the value of the new entry. Case 3 would need an SQL query on the jos_tags table.
I dont have enough Fabrik PHP coding experience to make this approach work with acceptable effort. Hopefully someone can use my research to solve this issue.

I also tried to use the code hugh deleted in his last commit - but the variable '$defaultLabels' returns the ID of the tag in jos_tags in case 2 and '#fabrik#newEntry' in case 3 - which both wont make the new entry show up after an validation error.

Chris
 
I'm looking at this now. I'd pretty much come to some of the same conclusions as you, so it's a case of working out how to actually implement the fix(es) ...

-- hugh
 
OK, I see where Rob was going with his new code, but it isn't going to work, for the reason we figured, because if it's a new selection (that hasn't been saved), it doesn't exist in the repeat table for the element.

The code I commented I was trying is what I'm pretty sure is more like what is needed, but it needs work. But I'm out of time on this one, I'll have to raise another issue for Rob.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top