Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON Schema Field Order #1982

Closed
johnRambo2k14 opened this issue Dec 16, 2019 · 1 comment
Closed

JSON Schema Field Order #1982

johnRambo2k14 opened this issue Dec 16, 2019 · 1 comment
Labels

Comments

@johnRambo2k14
Copy link

Question
Is it possible to render fields in a specific order specified by a JSON schema? right now my API returns an object and its properties appear in a different order every-time I query it.

Is it possible to provide ngx-formly a JSON schema property to render those fields in a specified order?

example:

{
    "title": "Display Types",
    "type": "array",
    "items": {
        "type": "object",
        "required": [
            "id",
            "display"
        ],
        "order": ["id", "display"], //<--- Is it possible or already a feature to do something like this?
        "properties": {
            "display": {
                "description": "what is the display type?",
                "type": "string",
                "enum": [
                    "GRID",
                    "FORM"
                ]
            },
            "id": {
                "description": "Name of display type",
                "type": "string"
            }
        }
    }
}
@aitboudad
Copy link
Member

aitboudad commented Dec 16, 2019

To adjust the generated FormlyFieldConfig use one of the following options:

  1. pass the extra Formly config through widget property:
{
  "type": "string",
  "format": "date-time",
+ "widget": {
+   "formlyConfig": {
+     "templateOptions": { "type": "datetime-local" }
+   }
  }
}
  1. use a map option:
this.formlyJsonschema.toFieldConfig(
  schema,
+  {
+    map: (field: FormlyFieldConfig, schema: JSONSchema7) => {
+      if (schema.order) {
+        ...
+      }
+
+      return field;
+    },
   },
);

@aitboudad aitboudad mentioned this issue Mar 30, 2020
52 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants