? Pending

User tests: Successful: Unsuccessful:

avatar brianteeman
brianteeman
22 May 2019

If you have a field with a default value then there is no point in also setting it as required as it already has a value

avatar brianteeman brianteeman - open - 22 May 2019
avatar brianteeman brianteeman - change - 22 May 2019
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 22 May 2019
Category Administration com_content com_workflow Installation Front End Plugins
576b263 22 May 2019 avatar brianteeman fixes
avatar brianteeman brianteeman - change - 22 May 2019
Labels Added: ?
avatar brianteeman
brianteeman - comment - 22 May 2019

@Quy thanks - not sure what I was thinking. I also put back the required on the text fields even if they have a default

avatar Quy
Quy - comment - 22 May 2019

I have tested this item successfully on 59fee06


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

avatar Quy Quy - test_item - 22 May 2019 - Tested successfully
avatar brianteeman
brianteeman - comment - 23 May 2019

Updating branch to trigger drone

avatar wilsonge
wilsonge - comment - 25 May 2019

This is actually required. The serverside validation uses the required attribute to ensure the properties are present when submitting. Example rule with relevent lines: https://github.com/joomla/joomla-cms/blob/4.0-dev/libraries/src/Form/Rule/OptionsRule.php#L42-L48 (this stops people submitting forms through post requests etc with missing attributes)

avatar wilsonge wilsonge - close - 25 May 2019
avatar wilsonge wilsonge - change - 25 May 2019
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2019-05-25 07:33:23
Closed_By wilsonge
avatar brianteeman
brianteeman - comment - 25 May 2019

Makes no sense to me to mark a field as required when it always has a value.

avatar brianteeman
brianteeman - comment - 25 May 2019

And there is no consistency or documentation

avatar HLeithner
HLeithner - comment - 25 May 2019

It makes sense, because you prevent the user to submit an empty field and get an unexpected value.

avatar wilsonge
wilsonge - comment - 25 May 2019

It's not just about the client side validation. It's the server side validation. You can send a post request to most these endpoints without ever using the client interface and we still need to protect against that

avatar HLeithner
HLeithner - comment - 25 May 2019

I think Brian expects that the default value is used in this case.

avatar brianteeman
brianteeman - comment - 25 May 2019

Exactly. And the complete lack of consistency negates everything else

avatar HLeithner
HLeithner - comment - 25 May 2019

And that's not true, if I want to remove the value of a field I expect that it's empty afterwards and doesn't have the default value.

Changing this would automatically set every empty field to it's default and that is not what you want.

avatar brianteeman
brianteeman - comment - 25 May 2019

I stand by my comments

avatar HLeithner
HLeithner - comment - 25 May 2019

So you say its better to make it impossible to submit an empty string? Sorry that's nonsense.

avatar brianteeman
brianteeman - comment - 25 May 2019

If we need the field to have a value then it should be impossible to submit an empty string. The fact that you can submit empty strings in all sorts of places when we must have a value is why we have errors such as #24972

avatar HLeithner
HLeithner - comment - 25 May 2019

if we need a value we use the require attribute that's the reason it exists.

avatar brianteeman
brianteeman - comment - 25 May 2019

and as shown that is not consistent and causes problems because of your "nonsense" belief that you can submit an empty string.

I have closed this PR - you can deal with the fallout

avatar mbabker
mbabker - comment - 26 May 2019

So you say its better to make it impossible to submit an empty string? Sorry that's nonsense.

If a field is required, generally that means it must have a non-empty value, therefore submitting the field with an empty string should throw a validation error. Assuming you are able to misuse the required attribute of a form field, which has a semantic definition per the HTML standard, to communicate "this field must be submitted as part of the POST, but if it's empty that's perfectly OK" just proves you do not understand basic concepts of data validation.

Misusing the Form API to define structures for the webservices API and a validation layer is also architecturally incorrect, but as Joomla continues to be dominated by a bunch of amateurs who don't have the slightest grasp on architectural concerns or separation of responsibilities, it seems that is a perfectly acceptable approach to misuse an API because it conveniently does something close enough to what they want it to do. There is a reason every serious platform has a separate validation API not coupled to the workflow of submitting an HTML form, and I highly suggest you all find a "smart" PHP developer to create one for Joomla, since this community seems to believe it must own everything itself and has a hard time integrating anything third party, such as the validation components of a tried and true framework like Laravel or Symfony or Zend.

avatar HLeithner
HLeithner - comment - 26 May 2019

So you say its better to make it impossible to submit an empty string? Sorry that's nonsense.

If a field is required, generally that means it must have a non-empty value, therefore submitting the field with an empty string should throw a validation error. Assuming you are able to misuse the required attribute of a form field, which has a semantic definition per the HTML standard, to communicate "this field must be submitted as part of the POST, but if it's empty that's perfectly OK" just proves you do not understand basic concepts of data validation.

This it out of context, my concern is about the what brian wrote. remove required from form field if we have a default value, as he wrote I understand it that it's true for all fields or fields with even an empty option field.

And in this case you can't remove required, also formfield makes server side validation to have a consistent description of the form and input data on one place.

avatar mbabker
mbabker - comment - 26 May 2019

remove required from form field if we have a default value, as he wrote I understand it that it's true for all fields or fields with even an empty option field

The handling of this default value points out yet another critical architecture flaw in the Form API and the MVC interaction with said API. Ignoring the fact that everything that is in the Joomla\CMS\Form namespace today and everything outside of it that inherits from it should just be flat out deprecated and replaced because the entirety of the API is just so frickin' flawed, assigning a default value if a field is empty is not a step that belongs as part of the Form::filter() call; in the case of submissions it is a data validation step that should occur either before or after the submitted data is validated (you can decide what is contextually appropriate for your workflow, but it should most definitely be after filtering) and in the case of rendering a field that should be handled when figuring out what value to put into the field at runtime.

A required attribute is not required on a select list with no empty value or on a radio option where it is impossible to not submit that field with something chosen (generally because something is already pre-selected). You use other mechanisms of validation to ensure a value is set and is in the expected list, you don't misuse the required attribute. If your excuse is "but you need to assign a value to the field if you're submitting in other ways like a webservices API", then you're already screwing up by trying to re-use a form and data definition not suited for REST oriented contexts.

If everyone's ready to get off their high horses and stop ignoring things because the source is either @brianteeman or @mbabker this pull request is 100% architecturally correct and every response given as to why this pull request is wrong just demonstrates why the Joomla architecture is flawed. Fix your shitty code.

avatar brianteeman
brianteeman - comment - 26 May 2019

Thank you @mbabker I knew I wasn't talking rubbish

I stand by my comments

avatar brianteeman
brianteeman - comment - 5 Jul 2019

Your arguments for not removing the useless required field when there is a default value might be valid if it was consistently applied. By your arguments every field must be a required field. They're not because it would be a silly thing to do.

Why do you insist that the workflow default field must be required

label="COM_WORKFLOW_FIELD_IS_DEFAULT_LABEL"

When the equivalent field for a menu item is not

Why do you insist that the workflow published field must be required

When no other published field is required

Finally making a field required in the form does not ensure that the data submitted is valid.

Add a Comment

Login with GitHub to post a comment