Looking for ideas -> Don't submit/save record if any element validation fails

Mustafa_s

Member
Hi,

I'm looking for a way to ensure users cannot click the submit/save button if any of the form element validations fail. My main reason for wanting this is because I have 6 fileupload elements, where if I submit/save a record all 6 of the fileupload elements resets if there is a validation error, meaning I need to select the files when the page reloads. I know this is working as designed (for security reasons), where the fileupload elements reset the chosen files, but is there a work around?

Even if I use Ajax validation the behaviour is still the same, once the user hits the submit/save button the attachment fields reset if there is a validation error. Is there is a way to disable the submit/save button while there is an active validation error (such as: dropdown not selected, field not entered, etc).

Thanks!
 
Hmmm. It might be possible, as we do fire an event (fabrik.form.element.validation.complete) when the AJAX validation completes, which we pass the error array to. But you'd have to maintain state, probably adding a hash to the form object, and add / remove element ID's as the pass / fail validation, and enable / disable the submit button depending on whether that array is empty or not. Not super hard, but not entirely trivial.

It's something we might consider adding to the core, I've thought about it before, as there doesn't seem to be much point allowing the user to submit the form if we know one or more elements have failed validation.

It's an hour or so's work, though, and I'm kind of having to ration subscription time for new features at the moment.

-- hugh
 
Hugh,

That would be much appreciated it if you could find the time/effort to implement it, as it stands the AJAX validation option doesn't add much to the form since users are able to submit regardless of validation state.

Would there be other solutions I can look into from the top of your head, like would a Form PHP plugin OnBeforeProcess do the trick?

Thank you.
 
Nope, it'd need to happen on the page, no point trying to do it in a PHP plugin, as that's basically all a validation is.

I'll give it a quick go now, as I just thought of what might be a relatively quick and easy way of doing it. But if that doesn't work, it'll probably be at least a week before I can get to it.

-- hugh
 
Hugh,

Thank you for your efforts. Here are my findings after applying a full update from Github.

1) After enabling Ajax Validation and Toggle Submit in the Form Processing tab I tested the changes and it looks like it's working fine. When opening a new form to submit if any of the element validation fails the form then disables the button dynamically, really cool how this works. However, the validation has to actually fail for it to work. What I mean by that is the user has to actually click on the element field and move the cursor away from the element field onto the next (without entering/selecting any data inside the field) for a validation error to occur, only once this error is occurred/triggered does the Submit button get disabled.

That being said, the changes only work if there is an active validation failure (user has to click on the element and make the element fail). It does not work when the user forgets to enter data in a field that requires data (think 'is not empty' validation for example), so the Submit button stays active. The Ajax validation has to occur for the changes to work, but if the user forgets to enter data where data is required then the ajax validation error doesn't occur.

2) I get the following error (Only in list view when error reporting is set to Maximum in Joomla's Global Configuration):
Notice: Undefined property: stdClass::$displayValue in /home/domain/public_html/domain.com/components/com_fabrik/models/list.php on line 6113

Thank you.
 
Last edited:
The displayValue notice has been fixed in github already.

Not much we can do about users not filling in required fields without some fairly extensive work. Validations only trigger when the 'blur' or 'change' event is fired for the element, depending on the type of element. I think we'd have to add a "must validate" option to all validation rules. We couldn't just rely on assuming that if there is a validation, it must be run. For instance, if you have a "not empty" validation on an element which has a default value, it is already valid on new forms. Or if you are editing a form, all the elements will already be valid when the form is loaded. And it would be a pain for users to tab through the entire form just to trigger validations.

What might be possible would be an additional "must validate" option, so the submit button is not enabled until all those have been run regardless, probably with some visual indication that they need validation. And probably make that option a "No / Yes / Only on New" choice.

The only other option might be to use our submit broker (which handles things like uploading AJAX files after the submit button is pressed, before submitting) to run any "must validate" validations which haven't been run yet, and abort submission if any of them fail.

But any of these approaches are a fair amount of work, and would need one or more people to fund the development.

-- hugh
 
Thanks for the clarification Hugh, I can imagine the amount of work involved. Would it be possible to get an idea of the amount required to fund?

Not sure how many others would actively want this feature.
 
It'd probably be a couple of hours. Well, more than that, but I'd contribute the extra hours as it would be a useful addition to Fabrik.


Sent from my HTC One using Tapatalk
 
Thanks Hugh, would you mind telling me the monetary cost as well? You can PM/Email me the info if you would like. I think I should be okay to fund the feature given it fits my budget and your efforts.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top