ui: Field names missing in Model->getField, causing corrupt Exception message

In recent develop, example demos/form/form2.php don’t work:

  • First form can never be saved, as iso ~cannot be empty, nor~ cannot it be changed
  • If you deactivate all validation handling in onSubmit to make it work again, still it will throw an error Javascript Error Syntax error, unrecognized expression: #

The second form throws error Atk4\Ui\Exception: Callback requested, but never reached. You may be missing some arguments in request URL. on save.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (15 by maintainers)

Most upvoted comments

@mvorisek on the line under the link above, $row still has complete field elements with name in it. The command $field = $model->getField($fieldName) then returns an array which has name empty, but some other like short_name are there. So if you adjust getField to fill the array including the name, it should be alright.

@mvorisek @ibelar I found the reason for my issue: The Javascript Error Syntax error, unrecognized expression: # actually is caused in my case by a thrown Exception in the protected function _typecastSaveField(Field $field, $value)in Persistence.php at https://github.com/atk4/data/blob/975b27f4de756118860da069ffff103633cc7f3a/src/Persistence.php#L271

The Exception however is not properly shown, but then the above Javascript Error is shown only. Can you check how to make sure that thrown Exception are properly displayed and not with the unrecognized expressions?

This is likely du to Data\Field error and badly formatted ValidationException throw when Field::$name is equal to null and has nothing to do with javascript.

see: https://github.com/atk4/data/blob/develop/src/Field.php#L282

Perhaps a regular exception should be thrown when $name property is null.

Otherwise the ValidationException will try to execute this javascript expression : $("#atk_layout_maestro_form").form("add prompt","","Must not be null")

Which end up in showing the error message above because of the missing field name.

@mkrecek234 : Thanks for pointing out the error form2.php error. I will issue a fix for it. When you see this error, please check for Exception within your model.

I have already seen Javascript Error Syntax error, unrecognized expression: # somewhere during other issue debugging, this is definitely a bug that must be fixed.