Skip to content
This repository has been archived by the owner on Apr 30, 2018. It is now read-only.

Is it possible in the fields JSON to add predefined values for every every fields of the form? #757

Open
falinsin opened this issue Nov 8, 2017 · 3 comments

Comments

@falinsin
Copy link

falinsin commented Nov 8, 2017

Two simple questions

  1. When I load a form fields form a JSON, is it better practice load the predefined fields values populating the JSON model or There are ways to fill them from the JSON of fields, like some property for example like predefined-value or something like that?

  2. Is there a specific field in the JSON of fields where I can receive extra data from the server?
    

For example, data such as the modification date and the name of the person who made it. In general they are other data that do not have to do directly with the creation of the form.
Currently I add a new { .... } in the lis of field and it seem it works.

Thanks in advance

@falinsin falinsin changed the title Is it possible in the fields JSON to add predefined values for every every fields of teh form? Is it possible in the fields JSON to add predefined values for every every fields of the form? Nov 8, 2017
@gmanriqueUy
Copy link

gmanriqueUy commented Nov 8, 2017

Hi.

  1. There's a property called defaultValue that is maybe what you're looking for

  2. Can you elaborate more on this? Not understanding what's your use case.

@falinsin
Copy link
Author

Thank you very much for your help.

  1. your answer is very helpful and made my day

  2. For every field I need to collect several extra data i can use in the server side or server can send me in the listfield JSON. For example

{
                    key: "textarea",
                    type: "textarea",
                    className: "col-xs-12",
                    templateOptions: {
                        name_type:"Textarea field",
                        code_type:"textarea",
                        label: "",
                        placeholder: "",
                        required: false
                    }
                }

For example you can see properties name_type and code_type are extra data for my own use.

I insert all these new data inside templateOptions propertie and it is working.

It does not intercept with the generation of the form because it formly ignores them.

My question is :

Is there a specific or more appropriate variable in formly to insert this type of custom variables or is it correct as I am doing? I ask it just in case

Than you very much

@gmanriqueUy
Copy link

Ohh, I get it now.

According to docs, you can use either templateOptions (as you're using right now) or data.

From docs:

data (object): This is reserved for the developer. You have our guarantee to be able to use this and not worry about future versions of formly overriding your usage and preventing you from upgrading :-)

Personally, I'd use data because, as you said, it's just extra data is not needed to manipulate the form.

Use templateOptions under your own risk; maybe formly adds a name_type or code_type in future versions and it break your implementation. With data that's not going to happen. 😄

I hope this helps!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants