guillotinaweb / ngx-schema-form

HTML form generation based on JSON Schema
MIT License
485 stars 173 forks source link

Empty form fields are missing from the model obgect #384

Open AviFix opened 3 years ago

AviFix commented 3 years ago

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

daniele-pecora commented 3 years ago

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

AviFix commented 3 years ago

What do you mean? Does it contradict?

daniele-pecora commented 3 years ago

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

AviFix commented 3 years ago

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

daniele-pecora commented 3 years ago

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.

AviFix commented 3 years ago

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?

daniele-pecora commented 3 years ago

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

AviFix commented 3 years ago

Sure

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

daniele-pecora commented 3 years ago

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