guillotinaweb / ngx-schema-form

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

required not working ? #37

Open Gundarf opened 7 years ago

Gundarf commented 7 years ago

The "required" array of the schema doesn't seem to impact the validation of the form.

Am I missing something ?

rkoszalka commented 7 years ago

Hello, I don't know if you have found a fix for this problem.

The model.value array of form send and empty string "" instead of null for fields that are not filled. I've managed to find an workaround for this, for my required fields i'm setting an minLength of one.

SBats commented 7 years ago

Hi @raphaelkoszalka. Thank you for this workaround! We're investigating on this bug but it's nice to have a temporary fix for users

rkoszalka commented 7 years ago

@SBats, i've integrated TV4 with angular-2schema-form module, in that way i've managed to properly validate required properties.

If you're interested in the weekend i can open a pull request with that change (tv4 instead of z-scheme for validation).

I just can't do right now because i'll be working untill saturday morning on a project.

SBats commented 7 years ago

I must say I don't know yet well the whole module, and at the moment can't say I have an opinion on z-schema vs TV4. Maybe @fbessou or @ebrehault knows better about this specific point as they chose z-schema? From my point of view, if the functional scope is not lowered and it fixes bugs, I'm all in! :)

Of course, if you find time to make a PR, we'll be really glad about it! But no rush needed, so take the time you need and don't hesitate to ask questions.

fbessou commented 7 years ago

Hello there. @raphaelkoszalka, if you have extended the SchemaValidatorFactory class it shouldn't be hard to integrate tv4 in angular2-schema-form.

Currently, the ZSchemaValidatorFactory is hard coded in the FormComponent but it could be provided at module level to allow overriding.

At first, z-schema was chosen because of the set of features it provides and its performances: https://github.com/ebdrup/json-schema-benchmark

kianmeng-aft commented 7 years ago

hey there,

i am also facing the same issue , the minLength workaround works!!

but is it part of the plan to fix this in the future release instead of adding the minLength ??

lzoubek commented 7 years ago

Hi, I am also facing this issue, but I don't like minLength workaround. z-schema has already support for empty string validation. So I think the best solution is a possibility to inject custom implementation of SchemaValidatorFactory. I'll try to open a PR for it

lzoubek commented 7 years ago

PR https://github.com/makinacorpus/angular2-schema-form/pull/108

daniele-pecora commented 4 years ago

A custom SchemalValidatorFactory can new be defined via module providers.
Example:

...
import {SchemaFormModule, SchemaValidatorFactory, WidgetRegistry} from 'ngx-schema-form';
import {
  Custom_FixOptionalEmptyFieldsZSchemaValidatorFactory,
} from './cutsom-validator-factory';

@NgModule({
  providers: [
     ...
    {provide: SchemaValidatorFactory, useClass: Custom_FixOptionalEmptyFieldsZSchemaValidatorFactory}
  ],
  declarations: [ ... ],
  imports: [ ... ],
  bootstrap: [ ... ]
})

export class AppModule {
}