json-schema-form / angular-schema-form

Generate forms from a JSON schema, with AngularJS!
https://json-schema-form.github.io/angular-schema-form
MIT License
2.47k stars 653 forks source link

Use form to set type as number #781

Closed ayhlam closed 7 years ago

ayhlam commented 7 years ago

Bug

As a user/developer, when I set the schema of type of a field to be a string, then set the type to be a number in the form, then the generated input box should work completely as a number box. This is similar to the way the form can treat enums.

Expected behaviour

Similar to changing the form to type="select", changing the form to type="number" should allow the user to input numbers and integers even though the schema has type="string".

Actual behaviour

It returns an error Invalid type, expected string

Gist/Plunker/Demo

Demonstrate expected behavior with type="select" form and type="string" schema

Demonstrate error with type="number" form and type="string" schema

@json-schema-form/angular-schema-form-lead

joelwkent commented 7 years ago

Hi @ayhlam, thanks for your interest in ASF and thanks for your very detailed issue. It's great when people provide examples like this as it ensures there is no confusion.

The behaviour you are seeing is correct and there is no bug here. The schema defines the data model, structure, data types and validation. The form defines the UI. You can put a select (enum) on a schema data type "string" as the option selected is stored in the model as a string. But you cannot put a number input field on a schema data type "string" as they are different data types. You should use the "number" or "integer" type in your schema.

Anthropic commented 7 years ago

@ayhlam I agree, nice work on the issue, we appreciate it despite the resolution :)

Please re-open if you do not feel the question has been answered sufficiently.