Using custom json creating angular form and getting data - json

Hi I am using angular js to construct my application. I have one problem while generating dynamic form.
My json is :
{
lines :[ {
fields:[{
fieldType : "input",
labelName : "Test Label",
modelName : "testInput"
},{
fieldType : "select",
labelName : "Test Label",
options : "['opt1','opt2','opt3']",
modelName : "testSelect"
},{
fieldType : "checkbox",
labelName : "Test Label",
modelName : "testCheckbox",
options : '[{'key':'key1','value':'value1'}]"
}]
}
This is just sample json. In real time, it is more complex type. I am created separate component for all the Html Elements like "input","select","checkbox","radio"...
I am using Directives for all the input element. I am taking few details from parent scope of form to directive.
for eg:
Main Directive
<ui-form form-option='uiFormOption'></ui-form>
Above is the main directive. i am passing above json in this Main Directive.
Inside the directive, i am iterating all the lines and and calling respective directive to fill the components based on field type.
Here, in the Html component directives are creating isolated scope i need that too fine.
When i save this from, i need to get all the data in single object in ParentScope
something like
$scope.myFormData = {}; //Parent Scope controller.
when i click save, all the data must be collect. my problem is $scope in child directive. so model map not be aware to parent. How to achieve this...

I am not sure if I understood your question correctly, but two things popped in my mind, I am sure you tried them but just in case:
1- since you are able to get the data to the html components, bind the data directly to the object where you are collecting the data from, and since it is already accessible everywhere, you can just use it to format whatever response you need.
2- if no other option is available, you can use $scope.$root, I know it is not the best thing to do, but it is always the hack to get a shared scope for all your elements.
I hope this is what you are looking for, and in case it was not, please comment.

if you need to display dynamic form so fetch this kind of json object through API:
{
"status": "true",
"statusCode": 200,
"response": [
{
"sort_order": 0,
"control_name": "ion-select",
"label": "Select master OLT",
"type": "select",
"placeholder": "Select master OLT",
"name": "E0selectoption_master_olt",
"readonly": "True",
"required": "required",
"maxlength": "",
"minlength": ""
},
{
"sort_order": 1,
"control_name": "ion-select",
"label": "Select OLT port",
"type": "select",
"placeholder": "Select OLT port",
"name": "E1selectoption_olt_port",
"readonly": "True",
"required": "required",
"maxlength": "",
"minlength": ""
},
{
"sort_order": 2,
"control_name": "ion-select",
"label": "Select Parent node",
"type": "select",
"placeholder": "Select parent node",
"name": "E2selectoption_parent_node",
"readonly": "True",
"required": "required",
"maxlength": "",
"minlength": "",
"is_dependent": "true",
"masters": "gis_node",
"value": ""
},
{
"sort_order": 3,
"control_name": "ion-select",
"label": "Select child node",
"type": "select",
"placeholder": "Select child node",
"name": "E3selectoption_child_node",
"readonly": "True",
"required": "required",
"maxlength": "",
"minlength": "",
"is_dependent": "true",
"masters": "gis_node",
"value": ""
},
{
"sort_order": 4,
"control_name": "button",
"label": "submit",
"type": "submit",
"placeholder": "",
"name": "E4submit_btnsubmit",
"readonly": "False",
"required": "required",
"maxlength": "",
"minlength": "",
"is_dependent": "false",
"masters": "",
"value": ""
}
]
}
in the given response which is in JSON format.
so you can easily bind this data with our html

Related

ngx-Formly - Display first array input by default without initializing empty model

I am using ngx-formly's JSON Schema approach to build out custom forms (Angular 9 + ng-bootstrap + bootstrap 4). Our app has a lot of array inputs - some are nested even. I have used the custom array type code from https://formly.dev/examples/advanced/json-schema to implement the array display.
The rendering of the form based on the schema for array inputs - is correct in the sense that the hierarchy of nesting is as required. However in case of array inputs - the form fields do not appear until someone clicks on the add (plus) button to show the first set of inputs. From a UI standpoint, we need atleast one set of fields displayed even if the user does not enter any value for the array (these are not mandatory inputs).
So far from the documentation there seem to be two approaches
initializing a model object with an empty or null first item for the array seems to be the way to make the fields appear. But we would need to put in empty/dirty/untouched checks to not commit these fields to the backend.
we change the template in the array type definition file to show one empty set of fields by default. Have not tried this approach, not sure how the binding of array fields would work if displaying one set of fields is forced.
Is there another way we can achieve this - by using some option fields?
I seem to have found a solution :)
Need to put "defaultValue": [ "undefined" ].
Full code below.
{
"fieldGroup": [
{
"key": "driver_section",
"type": "repeatDrivers",
"defaultValue": [ "undefined" ],
"fieldArray": {
"fieldGroup": [
{
"key": "last_name",
"type": "input",
"className": "flex-2",
"defaultValue": "",
"templateOptions": {
"label": "Фамилия",
"required": true
}
},
{
"key": "first_name",
"type": "input",
"className": "flex-2",
"defaultValue": "",
"templateOptions": {
"label": "Имя",
"required": true
}
},
{
"key": "paternal_name",
"type": "input",
"className": "flex-2",
"defaultValue": "",
"templateOptions": {
"label": "Отчество",
"required": true
}
},
{
"key": "date_of_birth",
"type": "input",
"className": "flex-2",
"defaultValue": "",
"templateOptions": {
"type": "date",
"label": "Дата рождения",
"required": true
}
},
{
"key": "series_and_number_of_VU",
"type": "input",
"className": "flex-2",
"defaultValue": "",
"templateOptions": {
"type": "number",
"label": "Серия и номер ВУ",
"required": true
}
},
{
"key": "date_of_issue_of_the_current_VU",
"type": "input",
"className": "flex-2",
"defaultValue": "",
"templateOptions": {
"type": "date",
"label": "Дата выдачи действующего ВУ",
"required": true
}
},
{
"key": "year_of_issue_of_the_first_VU",
"type": "input",
"className": "flex-2",
"defaultValue": "",
"templateOptions": {
"type": "number",
"label": "Год выдачи первого ВУ",
"required": true
}
},
{
"key": "driver_license_changed",
"type": "checkbox",
"className": "flex-2",
"defaultValue": "",
"templateOptions": {
"label": "Водительское удостверение менялось в течение года",
"required": false
}
}
],
"fieldGroupClassName": "display-flex"
},
"templateOptions": {
"title": "Drivers",
}
}
],
"fieldGroupClassName": "display-flex"
}
It seems nicer to write like
"defaultValue": [ {} ]
, and it also works great

Directory users update clearing fields not included in resource

Google's documentation states that Users.update will only update fields included in the userResource object. https://developers.google.com/admin-sdk/directory/v1/reference/users/update
In my script, I am able to submit updates successfully, but when I do, fields not specified are cleared out. Here's an example:
Original user resource:
{
orgUnitPath=/,
...
"organizations": [
{
"name": "John",
"title": "developer",
"primary": true,
"department": "IT",
"location": "CA",
"description": "fulltime_employee",
"domain": "acme.com",
"costCenter": "123456"
}]
}
I want to update just one of the fields, title = 'Sr. Developer'. When I submit the partial userResource with Users.update, the rest of the fields within the array element are cleared even though they were not submitted.
Submitted userResource
{
orgUnitPath=/,
...
"organizations": [
{
"title": "sr. developer"
}]
}
Updated user
{
orgUnitPath=/,
...
"organizations": [
{
"name": "",
"title": "sr. developer",
"primary": true,
"department": "",
"location": "",
"description": "",
"domain": "",
"costCenter": ""
}]
}
Is there a way to correct this, or do I need to load each field within the element and submit them all with only the changed fields updated?

Json schema field order

I know that fields listed in a json schema object have no defined order, since they are not an array, but I am looking for a way to be able to display them in the proper order in my application UI.
Workarounds I have found so far include things like using a different serializer, or even hard-coding a number into the field name.
I would like to come up with something that works with my current setup.
Hibernate, Spring Boot, and a react-app front end.
given this GET request:
/profile/personEntities
with header: Accept: application/schema+json
I will receive this:
{
"title": "Person entity",
"properties": {
"birthday": {
"title": "Birthday",
"readOnly": false,
"type": "string",
"format": "date-time"
},
"lastName": {
"title": "Last name",
"readOnly": false,
"type": "string"
},
"address": {
"title": "Address",
"readOnly": false,
"type": "string",
"format": "uri"
},
"firstName": {
"title": "First name",
"readOnly": false,
"type": "string"
},
"email": {
"title": "Email",
"readOnly": false,
"type": "string"
},
"cellPhone": {
"title": "Cell phone",
"readOnly": false,
"type": "string"
}
},
"requiredProperties": [
"firstName",
"lastName"
],
"definitions": {},
"type": "object",
"$schema": "http://json-schema.org/draft-04/schema#"
}
I have tried adding #JsonProperty(index=2) to the field, but nothing changes.
Thank you much for any tips.
If you're using Jackson to handle your serialization/deserialization you can use #JsonPropertyOrder - from their docs:
// ensure that "id" and "name" are output before other properties
#JsonPropertyOrder({ "id", "name" })
// order any properties that don't have explicit setting using alphabetic order
#JsonPropertyOrder(alphabetic=true)
See: http://fasterxml.github.io/jackson-annotations/javadoc/2.3.0/com/fasterxml/jackson/annotation/JsonPropertyOrder.html

Shopify - can i use a reusable variable list in settings_schema.json?

I would like to create a variable for a list of select options that can be re-used for multiple settings. example (variable state_list in the code below)...
{
"name": "Shop page",
"settings": [
{
"type": "header",
"content": "State"
},
{
"type": "select",
"id": "state_select",
"label": "Choose State...",
"options": state_list,
"default": "Alabama",
"info": "info text here"
}
]
}
and then (obviously) somewhere else, define that list. something like this...
var state_list = [
{
"group": "states",
"value": "AL",
"label": "Alabama"
},
{
"group": "states",
"value": "AK",
"label": "Alaska"
},
{
"group": "states",
"value": "AZ",
"label": "Arizona"
}
etc.
]
please - someone tell me this is possible!
You can't use variables in the schema object.
The schema objects accepts only JSON syntax and you can't pass any liquid variables in it.
This applies for the settings_schema.json file and the {% schema %} section.
You can't pass any liquid object, translatable strings or anything other piece of data that is not static text (a.k.a JSON object).
So if you are trying to do the following, it's INVALID:
{
"type": "select",
"id": "select",
"label": "Select",
"options": [
{{ select_options }}
],
"default": "option"
}

Using a web API in task.json to fill picklists buildtask

I am a first time TFS/VSTS extension developer. My Current task is to build a simple VSTS Build task.
We have a self made web API containing product information, but I am stuck in source binding. Found information about using the endpoint service, but my picklist aren't populated.
What i have so far:
Task.Json
"inputs": [
{
"name": "APIURL",
"type": "connectedService:Generic",
"label": "API URL",
"required": true,
"GroupName": "WebAPIsettings",
"helpMarkDown": ""
},
{
"name": "List1",
"type": "pickList",
"label": "List1",
"defaultValue": "",
"required": true,
"GroupName": "WebAPIsettings",
"helpMarkDown": ""
},
{
"name": "List2",
"type": "pickList",
"label": "List2",
"defaultValue": "",
"required": true,
"GroupName": "WebAPIsettings",
"helpMarkDown": ""
}]
,"sourceDefinitions": [
{
"target": "List1",
"endpoint": "/api/data/get",
"selector": "jsonpath:$.[Code]",
"authKey": "$(APIURL)"
},
{
"target": "List2",
"endpoint": "/api/data/get",
"selector": "jsonpath:$.[ID]",
"authKey": "$(APIURL)"
}]
I've created an generic endpoint that points towards the API (http://sample.api.local)
Both list1 and list2 are not populated after selecting the endpoint, so i'm missing something.
I've tested my API json output with http://jsonpath.com/
JSON test data:
[{"Code":"0344","ID":"version1"},
{"Code":"0363","ID":"version2"},
{"Code":"0518","ID":"version3"},
{"Code":"0599","ID":"version4"}]
What am I missing?
Using this code instead:
"selector": "jsonpath:$[*].ID"