ngx-schema-form icon indicating copy to clipboard operation
ngx-schema-form copied to clipboard

Empty form fields are missing from the model obgect

Open AviFix opened this issue 3 years ago • 9 comments

Hi,

When leaving a field empty, its property seems to be removed from the form value.

Regular angular form: image firstName is empty but is exist

ngx-schema-form: image

email is empty and not showing in the model object.

Thanks

AviFix avatar Feb 07 '21 22:02 AviFix

That is true, but how could it be handled otherwise and maintain the required validation?

daniele-pecora avatar Feb 08 '21 19:02 daniele-pecora

What do you mean? Does it contradict?

AviFix avatar Feb 08 '21 20:02 AviFix

Partially it does, because required wouldn't trigger if field is empty, only triggers if field is not present.

daniele-pecora avatar Feb 08 '21 20:02 daniele-pecora

Isn't it possible to trigger the required if the field is empty like the angular form control does?

AviFix avatar Feb 08 '21 21:02 AviFix

ngx-schema-form doesn't rely on angular form control validation rather on a json schema validator. The default validator implementation is Z-Schema. JSON Schema validation counts an empty property as present and therefore the required rule is passed as 'valid'. A 'required' validation is negative only if the required property is not present at all.

daniele-pecora avatar Feb 08 '21 23:02 daniele-pecora

Thanks for the detailed explanation.

Could you please point me to the code that is in charge of removing the empty fields and to the validation part?

AviFix avatar Feb 09 '21 08:02 AviFix

I don't know it myself. For preventing a huge breaking change this should end in a feature that can optionally be activated. Maybe via forRoot(...) or smt else

daniele-pecora avatar Feb 09 '21 08:02 daniele-pecora

Sure

Anyone else that can point me toi the code that is in charge of removing the empty fields and to the validation?

AviFix avatar Feb 18 '21 09:02 AviFix

@AviFix I would guess that widget.ts could be a good start (just guessing)

daniele-pecora avatar Feb 18 '21 16:02 daniele-pecora