Review main Abandoned

86389[TASK] Slim down FormEngine validation module

Andreas Kienast CR 0 V 0 Expert +829 −684 updated 04/01/25, 11:26

Commit message

Over the years, the JavaScript-based FormEngine validation grew beyond
its original purpose, which makes necessary refactoring pretty hard.

The main goal is to extract parts from the FormEngine validation to
better suited modules and make the actual module smaller.

The module is declared as `internal`. However, extensions still may use
certain methods as discovered by a TER code search. Therefore, explicit
deprecations are in place.

Review

  • Code review CR 0
  • Verified V 0

Issues 1

Files 36

Show 16 more files

Review log 5184

Show 3859 earlier messages
  1. Andreas Kienast uploaded patch set 1 10/01/24, 07:54

  2. Andreas Kienast uploaded patch set 2 10/01/24, 07:56

  3. core-ci voted on patch set 2 V -1 10/01/24, 08:05 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/66880

  4. core-ci voted on patch set 1 V -1 10/01/24, 08:05 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/66879

  5. Andreas Kienast uploaded patch set 3 V -1 10/01/24, 12:54

  6. core-ci voted on patch set 3 V -1 10/01/24, 13:01 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/66892

  7. Andreas Kienast uploaded patch set 4 V -1 10/01/24, 13:05

  8. core-ci voted on patch set 4 V -1 10/01/24, 13:10 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/66893

  9. Andreas Kienast uploaded patch set 5 V -1 10/01/24, 13:44

  10. core-ci voted on patch set 5 V -1 10/01/24, 13:49 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/66897

  11. Andreas Kienast uploaded patch set 6 V -1 10/01/24, 15:13

  12. core-ci voted on patch set 6 V -1 10/01/24, 15:18 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/66904

  13. Andreas Kienast uploaded patch set 7 V -1 10/02/24, 07:10

  14. core-ci voted on patch set 7 V -1 10/02/24, 07:15 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/66947

  15. Andreas Kienast uploaded patch set 8 V -1 10/02/24, 09:21

  16. core-ci voted on patch set 8 V -1 10/02/24, 09:29 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/66959

  17. Andreas Kienast uploaded patch set 9 V -1 10/02/24, 09:45

  18. core-ci voted on patch set 9 V +1 10/02/24, 09:53 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/66964

  19. Andreas Kienast uploaded patch set 10 V +1 10/02/24, 10:30

  20. Andreas Kienast uploaded patch set 11 10/02/24, 10:31

  21. core-ci voted on patch set 10 V -1 10/02/24, 10:36 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/66969

  22. core-ci voted on patch set 11 V -1 10/02/24, 10:38 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/66970

  23. Andreas Kienast rebased onto patch set 12 V -1 10/02/24, 10:39

  24. core-ci voted on patch set 12 V +1 10/02/24, 10:44 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/66971

  25. Markus Klein updated the commit message in patch set 13 V +1 10/04/24, 11:04

  26. Markus Klein commented on patch set 14 10/04/24, 11:10

    Published edit on patch set 13.
  27. Markus Klein voted on patch set 14 CR +1 10/04/24, 11:11

  28. core-ci voted on patch set 13 V +1 10/04/24, 11:20 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/67073

  29. Andreas Kienast commented on patch set 14 10/04/24, 11:26

    Deprecation-105184-MethodsInFormEngineValidationModuleExtracted.rst:21

    m(
  30. core-ci voted on patch set 14 V -1 10/04/24, 11:27 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/67074

  31. core-ci voted on patch set 14 V +1 10/04/24, 11:42 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/67074

  32. Andreas Kienast uploaded patch set 15 CR +1 V +1 10/11/24, 15:01

  33. core-ci voted on patch set 15 V +1 10/11/24, 15:08 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/67608

  34. Andreas Kienast rebased onto patch set 16 V +1 10/15/24, 13:10

  35. core-ci voted on patch set 16 V +1 10/15/24, 13:16 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/67839

  36. Andreas Kienast uploaded patch set 17 V +1 10/17/24, 08:54

  37. core-ci voted on patch set 17 V +1 10/17/24, 09:00 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/67912

  38. Ayke Halder commented on patch set 17 10/21/24, 07:53

    As the return type of "integer"-processing is changed here: Number-inputs don't give visual feedback of any conversion anymore. User can not be sure the number is stored as intended - especially in Firefox. See for details: * 86660: [BUGFIX] Respect already declared return type in `FormEngineValidation` | https://review.typo3.org/c/Packages/TYPO3.CMS/+/86660

    form-engine.ts:1381

    Breaking change here in combination witht the type-change for "integer"-processing.

    processor.ts:106

    This implements a change of return type! **Before `number`:** ```js returnValue = Processor.parseInt(value); ``` **Now `string`:** ```js `returnValue = String(Processor.parseInt(value)); ```
  39. Andreas Kienast commented on patch set 17 10/21/24, 08:16

    processor.ts:106 Reply

    I will happily remove this again if you can explain me how it could've worked before. `FormEngineValidation.processValue` was declared to return a string, but the `integer` case compiled with a `parseInt`. However, even for number fields, `.value` returns a string-based value, as opposed to `.valueAsNumber.`
  40. Ayke Halder commented on patch set 17 10/21/24, 08:36

    processor.ts:106 Reply

    It's all about TypeScript is not Javascript. So Typescript somehow did not recognize the type error. And Javascript does not evaluate any type-hints. You can actually make TypScript recognize this error by introducing types to `FormEngineValidation`. Just checkout the following change on top of the current `main`-branch and TypeScript will recognize the wrong use of `string`/`number` in `Build/Sources/TypeScript/backend/form-engine-validation.ts` (At least PhpStorm recognizes the error.) * 86663: [TASK] Introduce type FormEngineValidationType | https://review.typo3.org/c/Packages/TYPO3.CMS/+/86663 I assume Typescript does not recognize such errors as the use of `any` is really evil: ``` const FormEngineValidation: any = { ```
  41. Ayke Halder commented on patch set 17 10/21/24, 08:50

    processor.ts:106 Reply

    Just try this one: 86670: [POC] Introduce type FormEngineValidationType - error string/number | https://review.typo3.org/c/Packages/TYPO3.CMS/+/86670 And `./Build/Scripts/runTests.sh -s buildJavascript` fails with: ``` Sources/TypeScript/backend/form-engine-validation.ts:480:11 - error TS2322: Type 'number' is not assignable to type 'string'. 480 returnValue = FormEngineValidation.parseInt(value); ~~~~~~~~~~~ ```
  42. Andreas Kienast uploaded patch set 18 V +1 10/28/24, 07:37

  43. core-ci voted on patch set 18 V +1 10/28/24, 07:42 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/68709

  44. Ayke Halder commented on patch set 18 V -1 10/28/24, 16:32

    This one breaks the already implemented behaviour of "correctly formatting any number input for integer" in the visible field: See https://review.typo3.org/c/Packages/TYPO3.CMS/+/86660/comment/df4224b4_3d8225bd/ > An acceptance test might look like this: > > Use a form input-element format=integer (e.g. styleguide TCA demo -> elements basic -> tab: number -> field: number_2) > * Put in value 2, then unfocus. > * Check that the value in the visible field is 2. > * Put in value 2.5, then unfocus. > * Check that the value in the visible field is 2 again and not 2.5. > > The hidden input that goes to the database has always the value 2, for both the visible values 2 and 2.5. > > Current state of this change is, that the visible field is not updated, as the hidden value did not change. And thereby the visible value still shows 2.5 - whereas 2 from the hidden field is stored to the databse.
  45. Andreas Kienast commented on patch set 18 10/28/24, 16:58

    Reply

    Excuse me? You’re referring to a patch that isn‘t even merged. Claiming it breaks „correctly implemented behavior“ is therefore a false statement. I have the strobg feeling you‘re blocking my patches for the sake of getting yours in first.
  46. Ayke Halder commented on patch set 18 10/28/24, 17:09

    I recommend to get `any` fixed. Not having any `any` in the code will really improve the insights for TypeScript code checks.

    form-engine-validation.ts:45

    As this is already a big refactoring: please remove the evil `any` here and add a nice type configuration. Just copy paste the lines from this change, which are still necessary after the refactoring here: https://review.typo3.org/c/Packages/TYPO3.CMS/+/86670

    form-engine-validation.ts:89

    Better do not use `any`. E.g. specify `rules` like this: ``` const rules: [{ type: 'required'|'range'|'select'|'category'|'group'|'folder'|'inline'|'min'|'null' minItems?: string|number|null, maxItems?: string|number|null, lower?: string|number|null, upper?: string|number|null }] = JSON.parse(field.dataset.formengineValidationRules); ``` And then make the calculations which do an automatic conversion use the "unary operator" `+`: ``` minItems = +rule.minItems; // instead off `rule.minItems * 1` ```

    form-engine.ts:49

    Just get `any`removed and add all the functions with their correct arguments here. These functions are added later on - e.g. `FormEngine.openPopupWindow = function(mode: string, params: string, entryPoint: string): ModalElement {` Therefore we can do a trick and declare them all as optional via question mark `?` - e.g.: `openPopupWindow?: (mode: string, params: string, entryPoint: string) => ModalElement,` This still makes TypeScript correctly check the code for wrongly used types.

    helper.ts:2

    Any reason for not activating the type?
  47. Ayke Halder commented on patch set 18 10/28/24, 17:16

    Reply

    Get TYPO3 main. Open Firefox and go to any `type=integer` field in the backend. 1. Insert `2` - then unfocus. 2. Insert `2.5` then unfocus. 3. See how it jumps back to showing `2`. With this change here, it does not jump back to `2` - but stays at `2.5`. That's what I mean by breaking „correctly implemented behavior“. ---- I'm always okay with decisions like: "We make this new anyway. We can merge the current state and then improve afterwards, as this is a brand new `main`-branch anyway." But we just have to keep in mind that something will be broken - which needs fixing in the future.
  48. Andreas Kienast commented on patch set 18 10/28/24, 17:25

    Reply

    The whole patch is just for extracting stuff. This is step 1. The whole validation will face more smaller refactoring patches, some things will not be there anymore at a later point.

    helper.ts:2 Reply

    it is a plain extraction from the old code.
  49. Ayke Halder commented on patch set 18 10/28/24, 17:56

    Reply

    Then maybe don't change `"integer"`-handling, as this really introduces a change of the UI-behaviour. ** Before:** ``` case 'integer': if (value !== '') { returnValue = FormEngineValidation.parseInt(value); // returnValue is `number` } break; ``` **Introduced with this change:** ``` case 'integer': if (value !== '') { returnValue = String(Processor.parseInt(value)); // returnValue is `string` } break; ``` In combination with this it makes a difference: ``` State before checking: * hidden-field contains value "2" * human-readable-field contains value "2.5" dataHandlerField.value = "2" // `string` newValue = 2 // Before: `number` newValue = "2" // With this change: `string` if (dataHandlerField.value !== newValue) { * Before: this code here is executed. * With this change: this code is not executed. --> Update all the fields with the calculated value. } State after checking: * hidden-field contains value "2" * Before: human-readable-field contains value "2" * With this change: human-readable-field still contains value "2.5" ```
  50. Andreas Kienast abandoned the change 10/28/24, 18:13

    I give up…
  51. Ayke Halder commented on patch set 18 10/28/24, 18:35

    This change should not be abandoned as the refactoring here really improves the code. I'm open for a talk on why this escalated. You can reach out on Slack.
  52. Garvin Hicking commented on patch set 18 10/28/24, 19:09

    Reply

    Really sorry to read this unfold here. I would love to chime in and try to relay (and relax) but I sadly don't understand half of the workings here. 🥴 I do think following up on this approach and getting the first step made would be very helpful, to get more people on board of this beast and be able to improve areas.
  53. Ayke Halder commented on patch set 18 10/29/24, 19:59

    Reply

    Outsourced to: 86822: [BUGFIX] Return string in FormEngine `integer` parsing | https://review.typo3.org/c/Packages/TYPO3.CMS/+/86822
    Comment section cleaned up from things that need theire own changes.

    Reply

    Outsourced to: 86822: [BUGFIX] Return string in FormEngine `integer` parsing | https://review.typo3.org/c/Packages/TYPO3.CMS/+/86822

    Reply

    `"integer"` outsourced to: 86822: [BUGFIX] Return string in FormEngine `integer` parsing | https://review.typo3.org/c/Packages/TYPO3.CMS/+/86822 `any`-fixing is some bigger job for the future.

    form-engine-validation.ts:45 Reply

    `any`-fixing is some bigger job for the future.

    form-engine-validation.ts:89 Reply

    `any`-fixing is some bigger job for the future.

    form-engine.ts:49 Reply

    `any`-fixing is some bigger job for the future.

    form-engine.ts:1381 Reply

    Outsourced to: 86822: [BUGFIX] Return string in FormEngine `integer` parsing | https://review.typo3.org/c/Packages/TYPO3.CMS/+/86822

    processor.ts:106 Reply

    Outsourced to: 86822: [BUGFIX] Return string in FormEngine `integer` parsing | https://review.typo3.org/c/Packages/TYPO3.CMS/+/86822
  54. Andreas Kienast restored the change 10/31/24, 11:58

  55. Andreas Kienast uploaded patch set 19 V +1 10/31/24, 11:58

  56. Andreas Kienast uploaded patch set 20 10/31/24, 12:00

  57. core-ci voted on patch set 19 V +1 10/31/24, 12:05 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/68916

  58. core-ci voted on patch set 20 V +1 10/31/24, 12:08 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/68917

  59. Andreas Kienast uploaded patch set 21 V +1 10/31/24, 12:09

  1. core-ci voted on patch set 21 V +1 10/31/24, 12:16 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/68919

  2. Andreas Kienast uploaded patch set 22 V +1 11/20/24, 16:04

  3. Andreas Kienast uploaded patch set 23 11/20/24, 16:06

  4. core-ci voted on patch set 22 V +1 11/20/24, 16:11 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/69812

  5. core-ci voted on patch set 23 V +1 11/20/24, 16:13 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/69813

  6. Andreas Kienast uploaded patch set 24 V +1 11/21/24, 09:16

  7. core-ci voted on patch set 24 V +1 11/21/24, 09:24 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/69903

  8. Andreas Kienast uploaded patch set 25 V +1 12/10/24, 15:32

  9. core-ci voted on patch set 25 V +1 12/10/24, 15:38 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/70867

  10. Andreas Kienast uploaded patch set 26 V +1 12/11/24, 08:48

  11. core-ci voted on patch set 26 V +1 12/11/24, 08:53 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/70897

  12. Andreas Kienast uploaded patch set 27 V +1 12/16/24, 10:01

  13. Andreas Kienast uploaded patch set 28 12/16/24, 10:04

  14. core-ci voted on patch set 27 V +1 12/16/24, 10:09 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/71176

  15. core-ci voted on patch set 28 V +1 12/16/24, 10:10 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/71177

  16. Andreas Kienast uploaded patch set 29 V +1 12/20/24, 10:15

  17. core-ci voted on patch set 29 V +1 12/20/24, 10:23 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/71503

  18. Andreas Kienast uploaded patch set 30 V +1 01/15/25, 08:23

  19. core-ci voted on patch set 30 V +1 01/15/25, 08:31 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/72507

  20. Andreas Kienast uploaded patch set 31 V +1 01/16/25, 09:09

  21. core-ci voted on patch set 31 V +1 01/16/25, 09:17 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/72552

  22. Andreas Kienast uploaded patch set 32 V +1 02/20/25, 16:07

  23. core-ci voted on patch set 32 V +1 02/20/25, 16:13 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/74472

  24. Andreas Kienast wrote 02/20/25, 16:31

    Topic set to FormEngine
  25. Andreas Kienast abandoned the change 04/01/25, 11:26

    There seems to be no common interest.