Angular Schema Form - Require Field if Integer Field is Not Null - javascript

I am trying to create a form using the Angular JSON Schema Form. I want one field (dropdown1) to be required when another field (number1) is populated. I am able to get the following form + schema working in the SchemaForm.io Sandbox, but when I put it into my site, the dropdown field is missing.
Here is my schema:
{
"type": "object",
"properties": {
"isChecked": {
"title": "checked?",
"type": "boolean"
},
"text1": {
"title": "text1",
"type": "number",
"minimum": 0,
"maximum": 100,
"condition": "model.isChecked"
},
"number1": {
"title": "number1",
"type": "number",
"minimum": 0,
"condition": "model.isChecked"
},
"dropdown1": {
"title": "",
"type": "string",
"enum": ["Days", "Months", "Years"],
"condition": "model.isChecked"
},
"comment": {"type": "string", "Title": "Comment"}
}
}
Here is my form:
[
"isChecked",
{
"key": "text1",
"type": "decimal",
"validationMessages": {
"maximum": "text1 must be 100 or lower.",
"minimum": "text1 must be 0 or higher.",
"required": "This field is required"
},
"required": false
},
{
"key": "number1",
"type": "number",
"validationMessages": {
"minimum": "number1 must be 0 or higher."
},
"required": false
},
{
"key": "dropdown1",
"required": false,
"condition": "model.number1 === null"
},
{
"key": "dropdown1",
"required": true,
"condition": "model.number1 > 0",
"validationMessages": {
"required": "dropdown1 is required."
}
},
{
"key": "comment",
"type": "textarea"
}
]

You can use the "dependencies" property (https://json-schema.org/understanding-json-schema/reference/object.html#property-dependencies). The example requires billing_address to be present when a credit_card is provided:
{
"type": "object",
"properties": {
"credit_card": {
"type": "number"
},
"billing_address": {
"type": "string"
}
},
"dependencies": {
"credit_card": [
"billing_address"
]
}
}
This implementation supports "dependencies":
https://github.com/dashjoin/json-schema-form
You can check out the online example here:
https://dashjoin.github.io/#/example/dependencies

Here is the solution I found:
"condition": {
"functionBody": "return model.number1 === undefined && model.isChecked"
}

Related

Create object paths from a deeply nested object (Schema)

I have an avro schema, which is a deeply nested object with the same (sub)-structure. It looks like this:
{
"type": "record",
"namespace": "company.car.v1",
"name": "CarV1",
"fields": [
{
"name": "plateNumber",
"type": "string"
},
{
"name": "ownerId",
"type": "string",
"keepThisField": "true"
},
{
"name" : "details",
"keepThisField": "true"
"type" : {
"type" : "record",
"name" : "DetailsV1",
"fields" : [
{
"name": "engine",
"type": {
"type": "record",
"name": "EngineV1",
"fields": [
{
"name": "size",
"type": "int",
"default": 0,
"keepThisField": "true"
},
{
"name": "valvesCount",
"type": "int",
"default": 0
}
]
}
},
{
"name" : "color",
"type" : "string",
"default" : "NONE"
},
{
"name" : "rimSize",
"type" : "int",
"default" : "NONE"
}
]},
"default" : {}
},
{
"name": "isBrandNew",
"type": "boolean"
}
]
}
I want to be able to generally get all the object paths of this object (Schema) in JavaScript. So having something like a extractPaths(avroSchema) which for the example above would return:
[
"plateNumber",
"ownerId",
"details.engine.size",
"details.engine.valvesCount",
"details.color",
"details.rimSize",
"isBrandNew"
]
The order of the strings does not matter obviously. Anyone has an idea how this can be achieved in JavaScript?
Use a recursive generator function for generate path string.
var schema = { "type": "record", "namespace": "company.car.v1", "name": "CarV1", "fields": [{ "name": "plateNumber", "type": "string" }, { "name": "ownerId", "type": "string", "keepThisField": "true" }, { "name": "details", "keepThisField": "true", "type": { "type": "record", "name": "DetailsV1", "fields": [{ "name": "engine", "type": { "type": "record", "name": "EngineV1", "fields": [{ "name": "size", "type": "int", "default": 0, "keepThisField": "true" }, { "name": "valvesCount", "type": "int", "default": 0 }] } }, { "name": "color", "type": "string", "default": "NONE" }, { "name": "rimSize", "type": "int", "default": "NONE" }] }, "default": {} }, { "name": "isBrandNew", "type": "boolean" }] }
function* extractPaths(schema, value) {
for (const { name, type } of schema.fields) {
let path = value ? `${value}.${name}` : name
if (typeof type == "object")
yield* extractPaths(type, path);
else
yield path
}
}
console.log([...extractPaths(schema)]);

Slack Block-kit Multi_users_select Remove defaults app

I implemented a slack bot with um field of type input(multi_users_select). I would like to remove defaults apps from the list select?
{
type: 'input',
element: {
type: 'multi_users_select',
action_id: input.actionId,
initial_users: input.initial_users,
},
label: {
type: 'plain_text',
text: input.text,
emoji: input.emoji,
},
};
Instead of type: 'multi_users_select' use "type": "multi_conversations_select" with filter as shown below to get only users in your workspace.
You can copy and paste the below code in block-kit builder to test on your own.
https://app.slack.com/block-kit-builder/
{
"title": {
"type": "plain_text",
"text": "Blocker-Bot"
},
"submit": {
"type": "plain_text",
"text": "Submit"
},
"type": "modal",
"callback_id": "custom_time_select",
"private_metadata": "private-data",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Test block with multi conversations select"
},
"accessory": {
"type": "multi_conversations_select",
"placeholder": {
"type": "plain_text",
"text": "Select conversations",
"emoji": true
},
"filter": {
"include": [
"im"
],
"exclude_bot_users": true
},
"action_id": "multi_conversations_select-action"
}
}
]
}
Update 05-Jul-21
Included various other types of select users without bots/apps
{
"type": "modal",
"title": {
"type": "plain_text",
"text": "My App",
"emoji": true
},
"submit": {
"type": "plain_text",
"text": "Submit",
"emoji": true
},
"close": {
"type": "plain_text",
"text": "Cancel",
"emoji": true
},
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Conversations type Select user"
},
"accessory": {
"type": "conversations_select",
"placeholder": {
"type": "plain_text",
"text": "Select a user",
"emoji": true
},
"filter": {
"include": [
"im"
],
"exclude_bot_users": true
},
"action_id": "users_select-action"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Multi Conversations type Select users"
},
"accessory": {
"type": "multi_conversations_select",
"placeholder": {
"type": "plain_text",
"text": "Select conversations",
"emoji": true
},
"filter": {
"include": [
"im"
],
"exclude_bot_users": true
},
"action_id": "multi_conversations_select-action"
}
},
{
"type": "input",
"element": {
"type": "multi_conversations_select",
"placeholder": {
"type": "plain_text",
"text": "Select users",
"emoji": true
},
"filter": {
"include": [
"im"
],
"exclude_bot_users": true
},
"action_id": "multi_users_select-action"
},
"label": {
"type": "plain_text",
"text": "Input type Select users",
"emoji": true
}
}
]
}
Currently, filtering is available for conversations select menu or conversations multi select menu.
https://api.slack.com/reference/block-kit/composition-objects#filter_conversations
May be you can write to feedback#slack.com and they can log it for future releases.

Post request with array

I want to test my Web API with a postman on the javascript app.
I have the following swagger.
"/attachment/erase": {
"post": {
"summary": "Erase ",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"parameters": [
{
"name": "folder",
"in": "query",
"type": "string",
"description": "folder('s) detail",
"required": true
},
{
"name": "type",
"in": "query",
"type": "string",
"description": "ABC or BCD",
"required": true
},
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"type": "object",
"required": ["files"],
"properties": {
"attachments": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
"description": "The file(s) to delete"
}
],
"responses": {
"200": {
"description": "file(s) erased."
}
}
}
}
So I send the following request :
with the following body :
In return, I get an error 415.
What I am doing wrong?
You're sending x-www-form-urlencoded when the API is expecting application/json.
How about passing a form-data parameter file, please refer the image

Unable to Implement angular-schema-form-signature

I'm unsure as to why an input field shows on the form when implementing this code.(ref: https://github.com/JamesGuthrie/angular-schema-form-signature)
This is my Schema:
{ "type": "object", "properties": { "signature": { "type": "string" } } }
This is my Form:
[
"name",
{
"type": "tabs",
"tabs": [
{
"title": "Tab1",
"tabType": "top",
"items": [
{
"title": "Signature",
"key": "signature",
"type": "signature",
"width": 500,
"height": 100,
"resetButtonText": "Clear signature"
}
]
}
]
}
]

json schema doesn't work for empty response body

I have write one schema to validate the response body. And set all the items as "required". But when the body return empty array, it till PASS, which supposed should be FAIL. Schema like this:
var schema = {
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "array",
"items": {
"$ref": "#/definitions/MyObject"
},
"definitions": {
"MyObject": {
"type": ["object"],
"properties": {
"transactionId": "integer",
"transactionType": "string",
"bpCode": "string",
"bpId": "string",
"postingDate ": "string",
"dueDate": "string",
"totalAmount": "number",
"balanceDue": "number",
"reconcileAmount": "number",
"debitCredit": "string",
"remarks": "string",
},
"required": ["transactionId", "transactionType", "bpCode", "bpId", "postingDate", "dueDate", "totalAmount", "balanceDue", "reconcileAmount", "debitCredit", "remarks"],
"additionalProperties": false
}
}
};
tests["Valid respong body schema"] = tv4.validate(data.body, schema);
The response like this:
{
"errorCode": null,
"errorMessage": null,
"body": []
}
You should exclude the empty array with:
"type": "array",
"minItems": 1
"items": {
"$ref": "#/definitions/MyObject"
}

Categories

Resources