Validation notEmpty doesn't work on Rating element

chris.paschen

Chris Paschen
I've got several rating elements on a page (no repeat groups or anything - just a simple form); however, the Validations | notempty doesn't appear to have any effect on the element. The form can be submitted without any rating being entered.
Also, there isn't any validation (required) icon showing on the front-end next to the label.

I am NOT using ajax validation (at this point).

Is there some limitation on this element with regards to the validations?
Or is there some other way to get validations to work on rating elements?
 
What site template are you using?

I can't replicate this with Protostar, although with I found some issues with Helix 3 to do with icon names that basically prevent rating at all. I've just committed a number of fixes that allow it to work with any template (with different icon names).

Here's the rating element working with a 'notempty' validation, in Helix 3 ...

https://www.screencast.com/t/wbjtLaouw

Sorry about the slow submission, my laptop is due a reboot - running the web server, PHP Storm and the browser on the same machine starts to bog down after a while. Especially as I tend to have zillions of Chrome tabs open, and dozens of those have dev tools open.

-- hugh
 
Well, the validations are working now, but the values are not being saved :-(

Could this be the same issue that you saw with Helix?
What should I look for to know if it is (js error?)
And if so, did you find a solution?

The strange thing is that it saved the form without a problem.
 
I haven't tried multiple rating elements on a form. It should work, but you never know. I'll try adding a second one on my test form.

Are you doing 'user' or 'creator' rating?

Are your issues when creating a new form, or editing?

-- hugh
 
We were using 'user' rating.

The way we have it set-up, the ratings are being done on form edit.
We have 5 rating elements on the form.
 
And when you say "the values are not being saved", do you mean the individual user ratings are not being stored in the #__fabrik_ratings table, or that the average value isn't being stored in the field on the form's table?

-- hugh
 
Just to explain that last question ... in 'user' rating mode, the individual ratings from each user are stored in the #__fabrik_ratings table (by list id, form id, row id, element id and user id). Each user can only rate once (if they rate again, it just changes their existing rating). Those ratings happen via AJAX as the user clicks the stars. The value displayed (and submitted with the form) is the average of all user ratings (not the one they applied). And actually the submitted value is ignored, and we re-calculate the user average before storing the data. Although the submitted value will be what any validations are applied against.

So ... upshots ...

1) Applying a "not empty" validation on a user rating isn't all that helpful, as the rating will have a value if any user has rated that row. It doesn't force "this" user to rate it.

2) The submitted value (and that saved in the form) isn't what this user selected, it's the average of all ratings.

-- hugh
 
Thanks for clearing this up.
Just following up ...
First to answer questions ...

No - not overriding the thumbs layouts
Values saved - none in the main field (i.e. the average value) - just storing "0".

And we realized what you just stated, that the not-empty validation doesn't 'work' in this instance due to the way this element is designed, which unfortunately doesn't do what we need.
(We actually need just ONE review per entry - so we just needed the review 'star visuals' for selection, but we didn't need the storing/averaging. And using the creator option doesn't work for our need either.)

What we ended up doing is just using the radio button with a button group and just show the values that we needed (in decimal labels).
The benefit here was that the radio button does more what we need, but also is a bit more 'battle tested'.
It also gave us the advantage that we could allow the users to select 1/2 level increments.
We also tried changing the option labels to stars using html-entities, but decided decimal values are the easiest to communicate the ratings to the users.
 
Yup, sounds like the right approach.

Hasn't been a waste of time though, as I've given the ratings element a lot of love, fixed a number of issues, migrated the list rendering to a layout using the same icons as the form layout, etc.

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

Thank you.

Members online

Back
Top