Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"mandatory" and "required" field properties need to be refactored #576

Closed
mvorisek opened this issue Apr 25, 2020 · 4 comments · Fixed by #899
Closed

"mandatory" and "required" field properties need to be refactored #576

mvorisek opened this issue Apr 25, 2020 · 4 comments · Fixed by #899

Comments

@mvorisek
Copy link
Member

mvorisek commented Apr 25, 2020

See #569 (comment)

Currently they are defined like:

  • mandatory - prevent null
  • required - prevent null and anything that evaluates with empty() to true

Currently there are two major issues:

  • the names are not self explanatory
  • two properties does not cover all use cases (we can not allow nullable non-empty field) and the values are not always valid (when required is set, mandatory can be false and can not be used for checking if the field can be null or not)
  • the currently implementation does not even work like it is defined - see "mandatory" null validation is not working #575

I and @DarkSide666 propose to fix all these issues by refactoring this functionality to these fields:

  • notNull - if true, field can not be set null or saved/exported when null is set by default
  • notEmpty - if true, field can not be empty. Emptines should be evaluated to true when (string)$v === '' or for numerical types if (float)$v === 0.0.

With this proposal strings like (space) are considered non-empty. This is good to not solve multiple functionalities at once and it was so also originally as empty(' ') is evaluated to false. This should be fixed by normalization #577 which should be processed first.

These properties are very commonly used and therefore maximum care need to be provided to them.

@DarkSide666
Copy link
Member

One thing to still think about is - should integer/float 0 be considered empty value or not.
Empty string value do not carry any useful information, but zero euros is zero euros - it's useful information.

@mvorisek
Copy link
Member Author

@DarkSide666 With numerical field '' would have no effect as this value can not be persisted. So my proposal is to always allow zero ˙0˙ or values like -0.0 in non-numerical fields.

@DarkSide666
Copy link
Member

DarkSide666 commented Apr 27, 2020

In non-numerical field of course. If strlen(trim($value))>0 then it's useful information in my opinion.

@mvorisek
Copy link
Member Author

In non-numerical field of course. If strlen(trim($value))>0 then it's useful information in my opinion.

Yes, but not all together, one reason why I opened #577 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants