FormIO - Dynamic labels for Text Field based on the input data of another text field - formio

In my form, I have 2 text fields, Based on the user input from the input field 1, the label of the 2nd field should change.
Input 1 label: Name
Input 2 label: User, Please enter your age
Now when the user enters the name as John, Label 2 should be changed from 'User, Please enter your age' to 'John, Please enter your age'.
`
{
"title": "Page 1",
"label": "Page 1",
"type": "panel",
"key": "page1",
"components": [
{
"label": "Name",
"key": "name",
"type": "textfield",
"input": true,
"tableView": true
},
{
"label": "{{ row.name}}, Please enter your age",
"redrawOn": "name",
"key": "age",
"type": "textfield",
"input": true,
"tableView": true
}
],
"input": false,
"tableView": false
}
`
If I set label to " {{row.name}}, Please enter your age",
Initially when the form load there will not be any data in the name field, so the 2nd label is " , Please enter your age".
Is it possible to have "user", i.e "User, Please enter your age" until the name value is entered?

Here is the workaround I followed
In the second field label, change the {{row.name}} to dummy variable {{data.name1}}
Change the second field redraw on based on the first field
Add the logic in the calculated values section when data.name is empty, set data.name1 value to "User", otherwise assign the data.name to data.name1
here is the snippet
if (data.name === "") {
data.name1="User";
}else{
data.name1=data.name;
}

Related

How do I add a code snippet with a number as a tabstop

Consider the following JSON schema snippet:
{
"label": "New spell",
"description": "Creates a new spell",
"body": {
"name": "$1",
"source": "$2",
"page": "${3}",
"tradition": "$4",
"type": "${5|U,A|}",
"level": "${6}",
"description": ["$7"]
}
}
Both page and level need to be an integer (can default to 0), but also be a tabstop. I have tried a few things, but the only value that acts as a tabstop is enclosed in quotes, so it ends up being a string.
Is there a way to add a tabstop where the default value is a number?
This would work to set a tabstop 3 and 6 with defaults of 0. Note that the quotes must be escaped.
"\"page\": \"${3:0}\""
Also the general form of a snippet is as follows:
"new spell": {
"description": "Creates a new spell",
// "scope": "javascript,typescript",
"prefix": "new spell", // whatever prefix you want
"body": [ // array
"\"page\": \"${3:0}\"",
"\"level\": \"${6:0}\"",
]
}
There is no label property and there should be a prefix property. And body, if multiple statements is an array.
As it says in the documentation:
If a string starts with ^, the string content will be inserted as-is, not stringified. You can use this to specify snippets for numbers and booleans.
The value string needs to be specified as "^${3:0}".
So, the snippet fixed:
{
"label": "New spell",
"description": "Creates a new spell",
"body": {
"name": "$1",
"source": "$2",
"page": "^${3:0}",
"tradition": "$4",
"type": "${5|U,A|}",
"level": "^${6:0}",
"description": ["$7"]
}
}

Can i add an index to a table in Tilda for performance?

We created a simple table in Tilda and want to create an index. How to do that?
{ "name": "Test"
,"description": "The table to keep track tests amd owners"
,"columns":[
{ "name": "id" , "type": "STRING" , "nullable": false, "size": 128, "invariant": true, "description": "The name of the test" }
,{ "name": "name" , "type": "STRING" , "nullable": false, "size": 128, "invariant": true, "description": "The name of the test" }
,{ "name": "test_fk" , "sameAs":"Test.refnum" , "nullable": false, "invariant": true, "description": "The name of the test" }
]
,"primary": { "autogen": true }
,"foreign": [
{ "name":"Test", "srcColumns":["test_fk"], "destObject":"Test" }
]
}
You can see documentation details about Index creation in table definitions in the Wiki:
https://github.com/CapsicoHealth/Tilda/wiki/Tilda-JSON-Syntax%3A-Object-Indices
// Within an Object definition, you can define any number of indices (or none).
"indices":[
// A unique index that exists in the database over colA and colB
{ "name":"Blah1", "columns":["colA", "ColB"], "db":true }
// A regular (non-unique) index that overlaps with the previous definition
// but only exists for application needs (no database definition).
,{ "name":"Blah2", "columns":["colA"] , "orderBy":["colB"], "db":false}
// A regular index with only an orderBy definition.
,{ "name":"Blah3", "orderBy":["colB"], "db":true }
]
The markup above shows the JSON to create a variety of indices with comments explaining what each attribute does.

Check for value in json array

I have a table of data which has a field called details which contains a json object.
The object looks something like this:
{
"name": "Persons Name",
"list": [
{
"name": "Persons Name",
"assigned": {
"company": "Company 1",
"number": "AA1"
}
},
{
"name": "Persons Name",
"assigned": {
"company": "Company 2",
"number": "BB2"
}
},
{
"name": "Persons Name",
"assigned": {
"company": "Company 3",
"number": "AA3"
}
}
],
"total_results": 3
}
Essentially, I want to return all data if any of the person's 'assigned'->>'number' field begins with an A. In the above example, two of the individuals numbers are prefixed with an A so I want all data returned.
I've been playing around and had have been making some progress but can't figure out how to bring it all together.
select f->'assigned'->>'number' from jsonb_array_elements((select details->'list' from table_name)) f;
The above query can get me a list of the three 'number' fields but I'm not sure how I can combine that with a query to return all the information, if any of these fields contain a prefix A
You are so close. Just add your condition in where clause.
SELECT *
FROM JSON_ARRAY_ELEMENTS((SELECT details -> 'list' FROM TABLE_NAME)) f
WHERE f -> 'assigned' ->> 'number' LIKE 'A%'
CHECK DEMO HERE

engati : Get button click value

Engati Chatbot question.
Engati tag is not exist yet so i manually add here.
I wanna try to get dynamic bank account number using custom code which shown as below
process({
"data": {
"type": "msg_options",
"text": "Choose an Account Number",
"options": [
{
"text": "12345678901234",
"postback": "flow_788224AF8006422BA5E587720DE3B252"
}, {
"text": "43210987654321",
"postback": "flow_788224AF8006422BA5E587720DE3B252"
}
]
}
});
Here in example i set two options and set same flow [flow_788224AF8006422BA5E587720DE3B252]
Now i want to get which option selected by user in flow_788224AF8006422BA5E587720DE3B252
Should i write any dynamic script for that or use any other options?
Resolved by below code
{
"data": {
"type": "msg_options",
"text": "Choose an option",
"options": [
{
"text": "12345678901234",
"postback": "flow_788224AF8006422BA5E587720DE3B252||data_account=12345678901234"
}, {
"text": "43210987654321",
"postback": "flow_788224AF8006422BA5E587720DE3B252||data_account=43210987654321"
}
]
}
}
Also you can user multiple variable like
"postback": "flow_788224AF8006422BA5E587720DE3B252||data_account=43210987654321&data_bank=ICICI"
data_ is set to define attributes
and use in send message with {{account}}

Task.Json triggers validation on invisible only fields

I am trying to create a Azure DevOps Pipelines Custom extension. I have a task.json where fields are visible on certain conditions.
For example:
{
"name": "actions",
"type": "picklist",
"label": "Actions",
"defaultValue": "Select",
"required": true,
"helpMarkDown": "Select an Action from the dropdown as per your requirement.",
"options": {
"New": "Add",
"Delete": "Delete"
}
},
{
"name": "backEndIPAddress",
"type": "string",
"label": "IP Address",
"required": true,
"defaultValue": "",
"helpMarkDown": "",
"visibleRule": "actions = New",
"validation": {
"expression": "isMatch(value,'^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?){0,15}$','IgnoreCase')",
"message": "Invalid IP Address. Please try again!"
}
}
The issue when the IPAddress field is hidden, the validation is still tried and it fails. How to ensure that the fields are validated only if they are visible?
A few options:
Set a default value for the input
Update the regex to include ^$| at the start to allow empty values ('require':true will take care of the requiredness)
Remember that there should be a default isIpV4Address(value: string) function so you don't have to specify the regex.
From the docs it looks like there is an upcoming when clause which will dictate when the set of rules should trigger, I suppose this may be causing the currently unwanted behavior.
See also:
https://github.com/Microsoft/vsts-tasks/blob/1d75fa8f66aa1cf7a9cb62946939f30f087b2969/docs/taskinputvalidation.md