What is the relationship between a circuit and a form in an angular diagram?

In my angular project, I need to dynamically create some forms. To do this, I did some search queries and found the angular-schema-form module. This seems to be exactly what I want, but the problem is that I donโ€™t understand how to save the layout and form. What is the relationship between circuitry and form?

I read the documentation from the types of forms , but this is not very useful to me. I do not want to use this module like HIT and TRY. First, I want to understand the concept: what is the relationship between the circuit and the form?

+8
source share
2 answers

To try to solve the main question:

What is the relationship between circuitry and form?

To make things simple, it might be easiest to think of it this way. To create a form, you have three parts of JSON:

  • JSON containing the actual data submitted through your form. This is a model .

  • JSON schema . This describes the structure of the model . To give an extremely simple example of the relationship between model and schema , imagine that your actual data (your model ) describes the person in terms of their gender and age, for example {sex: female, age: 32} . The role of schema is to describe the structure of the model, so in this case it would describe that there must be a sex property of a string type whose values โ€‹โ€‹can only be male or female , and that there is an age property, etc. To be able to submit a form filled with your model data, it just needs to have a schema to build the form in the first place.

  • JSON form is what I consider optional . You should have it, but it may just contain a "*" , which tells angular-schema-form simply create the form automatically based on the schema. In this case, the library will build a form completely based on the scheme, and using the default settings, as described in the documentation. But what you can do if you want, uses the form object to describe how you want to structure your form.

Here a very crude and very simple example of the flexibility of a form object gives you:

Taking an example of the person object above, if you are not using a form object (that is, it just contains a "*" ), then angular-schema-form build you a form based on the schema. So he would have input fields for sex and age . These fields may or may not be in format or order or have other properties that you want. Then you can optionally use the form object to instruct angular-schema-form how you want it to create the form. For example, you can use form to make it so that the form contains only a field for age , not sex .

So, model is your data, and schema describes the structure of this data. In a simplified form, form provides an additional layer of display and configuration to your form, overriding the default form, which will be created only based on schema .

Does it help?

+11
source

I had the same question as you, but no one could just understand my concern. I am not an AngualrJS guru or JSON guru, so I had a lot of difficulties understanding the manual and I found examples that are also confusing (for a beginner like me).

So, after many attempts and errors, this is what I understood:

A form is what the <FORM> structure will be when rendering.

A schema is a data structure strictly defined by this link: https://json-schema.org/understanding-json-schema/about.html.

It has much in common with the old XML dtd schema. When you define a schema, it determines how the data will be represented in the model. So if you define a circuit like this

 { "type" : "object", "properties" : { "contact" : { "title" : "$Contact", "type" : "number" } } } 

the model will present the contact as a numerical value. If you enter type as string, you will have a model represented in string format and so on.

0
source

Source: https://habr.com/ru/post/986538/


All Articles