?
avatar artur-stepien
artur-stepien
4 Jan 2019

Feature description

I was using showOn script/functionality from Joomla! in another project. After a while I wrote a conditional requirement script working exactly like showOn. I have no access to that code anymore but I think it would be a great improvement to the UI/UX. That would allow developer to make more responsive forms and let concentrate on form building instead of writing scripts. I think it is worth the discuss.

Expected result

A possibility to set field requirement based on another fields value exactly like it is working in showOn.

Additional comments

If there will be no volunteer and enough interest in the feature I will write that again and provide a proper PR.

avatar artur-stepien artur-stepien - open - 4 Jan 2019
avatar joomla-cms-bot joomla-cms-bot - labeled - 4 Jan 2019
avatar mbabker
mbabker - comment - 4 Jan 2019

The showon feature is entirely client side (browser) logic, it works great for what it is.

A requireon feature would need to work in both the client and server, that makes this type of behavior rather complex for a core system and I would suggest if you need it you are best suited writing a custom FormRule implementation for the server side validation.

avatar artur-stepien
artur-stepien - comment - 7 Jan 2019

@babker Correct me if I'm wrong. If we already have FormRule why not build requiredOn both client-side and server-side. Where the rules would apply both? JavaScript based on showOn for a front-end and a back-end processor building FormRule based on the field rules? That would require less code to write from a developer. Just build a form, write the rules in the form and that's it. The markup would be known cause of showOn. The FormRule does provide a $form object so you should be able to check other fields values conditionally. I see only 2 difficult parts in here. One is the ability to use FormRule build programicaly, that would probably require adjusting Form object definition. The second difficulty is translating potential java script requireOn rules to PHP. Nothing looks impossible, too complex or a potential problems generator. Not to mention that nothing has to be changed for a backward compatibility.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/23444.

avatar artur-stepien
artur-stepien - comment - 7 Jan 2019

@babker Correct me if I'm wrong. If we already have FormRule why not build requiredOn both client-side and server-side. Where the rules would apply both? JavaScript based on showOn for a front-end and a back-end processor building FormRule based on the field rules? That would require less code to write from a developer. Just build a form, write the rules in the form and that's it. The markup would be known cause of showOn. The FormRule does provide a $form object so you should be able to check other fields values conditionally. I see only 2 difficult parts in here. One is the ability to use FormRule build programicaly, that would probably require adjusting Form object definition. The second difficulty is translating potential java script requireOn rules to PHP. Nothing looks impossible, too complex or a potential problems generator. Not to mention that nothing has to be changed for a backward compatibility.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/23444.

avatar mbabker
mbabker - comment - 7 Jan 2019

A feature to conditionally show fields in the UI is majorly different from a feature to conditionally require fields.

Conditionally showing fields is a lot less processing power as it is mostly JavaScript listening for change events then toggling display: block; or display: none; on a UI element (breaking it down to the simplest thing).

Conditionally requiring fields is a lot more effort. In the browser at the absolute minimum this should be toggling the required attribute of a <input> or <select> element, possibly changing classes on it and its related <label> element depending on the UI framework and designer's preferences, and requires extra conditional processing of fields and the form itself on both client side submission (any onsubmit event listener) and the server side submission (save action). This bit is highly complex and honestly not an easy thing to provide a high level abstraction for that will suitably work for everyone (especially because it is going to turn into a "I need this field to be conditionally required if one of these three fields has X value" type of requests), which is why I suggest it is best left to a developer to implement locally.

If you have a conditionally required field, this is a perfect case for using extended server side validation and rejecting the submission if it fails. Trying to make a behavior that works in both client and server is asking for trouble.

avatar artur-stepien
artur-stepien - comment - 7 Jan 2019

@mbabker You over-complicating that. I already modified showOn once to archive that functionality and it wasn't as problematic as you say. The argument that single field should be required if one of 3 has a certain value is missed as showOn already allows to hide/show field using such rule. And I was using it both for required and show rules on a 40-80 fields form. The only new part is the server-side. And as we already have FormRule it can be used. Form is already processed server-side when it is saved and validation is fired. Your'e just extending the validation. But building a whole new login.

avatar mbabker
mbabker - comment - 7 Jan 2019

If someone really thinks they can build such a mechanism that will work with some of these edge cases that people throw at things, then by all means go for it. Personally, I really think conditionally required rulesets belong to your server side validation logic and isn't something that should leak into the client (I'm also one of those who uses the client for only basic validation and doesn't try to have my form validation rules in both the client and server) and I don't think this needs to be a core CMS feature.

avatar franz-wohlkoenig franz-wohlkoenig - change - 4 Mar 2019
Status New Information Required
avatar franz-wohlkoenig
franz-wohlkoenig - comment - 4 Mar 2019

@artur-stepien can this be closed?


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/23444.

avatar artur-stepien
artur-stepien - comment - 4 Mar 2019

@franz-wohlkoenig There is the usual "no cause of reasons" so I assume it can be closed.

avatar franz-wohlkoenig franz-wohlkoenig - change - 4 Mar 2019
Status Information Required Closed
Closed_Date 0000-00-00 00:00:00 2019-03-04 12:27:11
Closed_By franz-wohlkoenig
avatar joomla-cms-bot joomla-cms-bot - change - 4 Mar 2019
Closed_By franz-wohlkoenig joomla-cms-bot
avatar joomla-cms-bot joomla-cms-bot - close - 4 Mar 2019
avatar joomla-cms-bot
joomla-cms-bot - comment - 4 Mar 2019
avatar franz-wohlkoenig
franz-wohlkoenig - comment - 4 Mar 2019

Add a Comment

Login with GitHub to post a comment