DynamicForm validation - accept Validator_A OR Validator_B - smartclient

My DynamicForm field has 2 validators for zip code
[
{ type: "mask", errorMessage: "Invalid postal code", mask: "^(\\s*\\d{5}\\s*)(\\s*-?\\s*\\d{4}\\s*)?$", transformTo: "$1-$2" },
{ type: "mask", errorMessage: "Invalid postal code", mask: "^\\s*([A-Z]{1}\\d{1}[A-Z]{1})\\s*(\\d{1}[A-Z]{1}\\d{1})\\s*$", transformTo: "$1-$2" }
]
The first is for the United States, the 2nd is for Canada. Is It possible to set the field up to accept either option as valid input?

this answer is a bit old
but I think it's still valid.

Related

How can I retrieve nested values in Keystone 5 for my list

I'm adding a list called 'tourlocation' to my Keystone 5 project. In my mongo database my tourlocations collection has an object called 'coordinates', with two values: 'lat' and 'long'. Example:
"coordinates" : {
"lat" : 53.343761,
"long" : -6.24953
},
In the previous version of keystone, I could define my tourlocation list coordinates object like this:
coordinates: {
lat: {
type: Number,
noedit: true
},
long: {
type: Number,
noedit: true
}
Now unfortunately, when I try to define the list this way it gives the error: The 'tourlocation.coordinates' field doesn't specify a valid type. (tourlocation.coordinates.type is undefined)'
Is there any way to represent objects in keystone 5?
#Alex Hughes I believe your error says "type" which you may need to add it like this
keystone.createList('User', {
fields: {
name: { type: Text }, // Look at the type "Text" even in the MongoDB you can choose the type but it will be better to choose it here from the beginning.
email: { type: Text },
},
});
Note that noedit: true is not supported in version 5 of KeystoneJS.
For more info look at this page https://www.keystonejs.com/blog/field-types#core-field-types

Validate the json Array with Either one field required in Mule 4

Request Json Looks like the below :-
{
"eNumber": 8506493,
"details": [
{
"id":12345,
"name": xyz123
}
]
}
As part of requirement, I need to check the "details" array that either "id" or "name" field must present. if "id" field is present, "name" is non-mandatory. if "name" field is present, "id" is non-mandatory. Throws error if not met.
I tried few options using filter the details array and check the size of the filtered array in the validation component. It does not seems to be working well. if anyone has got better solutions.please share it here.
This example code will return true or false if it passes your condition
%dw 2.0
import * from dw::core::Arrays
output application/json
---
payload.details every ((item) -> item.id? or item.name?)
The function I'm using is every that checks that all elements in an array passes the given criteria.
Later you can use a choice and a use the raise error or you can use the fail dw function with an if else.
You can restrict it at RAML level.
Sample RAML -
#%RAML 1.0
title: api
types:
test1:
type: object
properties:
id:
type: string
example: 123a
test2:
type: object
properties:
name:
type: string
example: xyz124
test3:
type: object
properties:
enumber:
type: string
example: 8506493a
details :
type: [test1 | test2]
/test:
post:
body:
application/json:
type: test3

The provided key element does not match the schema. GraphQL Mutation error

I am trying to test/run a mutation that creates groupChat in my DynamoDB by id,groupChatName, messages, createdTime, createdUser, users. I have 2 seperate tables, UserTable and GroupChatTable.The problem is I keep getting data is null and an error that says "the provided key element does not match the schema. ErrorCode: Validation Exception, request ID." Resolvers are attached to my tables so I am not sure why I am getting this error.
The weird thing is when I check the groupChatTable, my mutation is saved incorrectly as an input.This is what it looks like,
Ex: {"createdTime":{"S":"12:00"},"createdUser":{"S":"Me"},........
Below is the Mutation,Schema type,and Resolver.
createGroupChat(input:{
id: 4
groupChatName: "newgroup"
messages: "we love this group"
createdTime:"12:00"
createdUser: "Me"
users:"we, me"
}) {
id
groupChatName
messages
createdTime
createdUser
users
}
}```
```type GroupChat {
id: ID!
groupChatName: String!
messages: String
createdTime: String!
createdUser: String!
users: String
}```
```{
"version" : "2017-02-28",
"operation" : "PutItem",
"key" : {
"id": $util.dynamodb.toDynamoDBJson($util.autoId()),
},
"attributeValues" : $util.dynamodb.toMapValuesJson($ctx.args)
}```
It looks like the way data is being stored through resolver is incorrect and when it returns it doesn't match the schema
Instead of using $util.dynamodb.toMapValuesJson(($ctx.args))
use: $util.dynamodb.toMapValuesJson($util.parseJson($util.toJson($ctx.args.input)))

what is the proper way to validate all elements of an array in the query parameters even with 1 element with express-validator?

Using express-validator version 5.3.0.
I love the new syntax and I want to validate that a query parameter is valid. That parameter can be an array (as in repeat parameter).
The issue I have is that when only 1 element is passed, the framework seems to just consider it a string and the error message(s) is(are) a bit cumbersome.
with this configuration:
checkSchema([
{
foo: {
in: 'query',
isAlphanumeric: true,
optional: true,
errorMessage: 'Invalid foo'
}
}])
with the url http://server/api?foo=bar&foo=not bar I get the following error:
{
"location": "query",
"param": "foo[1]",
"value": "not bar",
"msg": "Invalid foo"
}
which seems correct.
However with the url http://server/api?foo=not bar I get the following error:
{
"location": "query",
"param": "foo[3]",
"value": " ",
"msg": "Invalid foo"
}
It's not a huge deal, but the foo[3] param is a bit misleading as technically is either just foo or foo[0].
I tried with isArray: true like below, but no luck:
foo: {
in: 'query',
isArray: true,
isAlphanumeric: true,
optional: true,
errorMessage: 'Invalid foo',
},
But that seems to actually ignore the second foo parameter (because technically a string is an array of characters?).
And with the single parameter version foo=no bar it shows the error message twice (I assume because the validator fails for both isArray and isAlphanumeric?)
Alright, so, it looks like express-validator was updated since then and now provides a toArray sanitizer.
So now, I can write the following:
checkSchema([
{
foo: {
in: 'query',
optional: true,
toArray: true,
},
'foo.*': {
in: 'query',
isAlphanumeric: true,
optional: true,
errorMessage: 'Invalid foo'
}
}])
And as an added bonus, it will now always convert queries with 1 parameter to an array of 1 value.

Collapsing a group using Google Sheets API

So as a workaround to difficulties creating a new sheet with groups I am trying to create and collapse these groups in a separate call to batchUpdate. I can call request an addDimensionGroup successfully, but when I request updateDimensionGroup to collapse the group I just created, either in the same API call or in a separate one, I get this error:
{
"error": {
"code": 400,
"message": "Invalid requests[1].updateDimensionGroup: dimensionGroup.depth must be \u003e 0",
"status": "INVALID_ARGUMENT"
}
}
But I'm passing depth as 0 as seen by the following JSON which I send in my request:
{
"requests":[{
"addDimensionGroup":{
"range":{
"dimension":"ROWS",
"sheetId":0,
"startIndex":2,
"endIndex":5}
}
},{
"updateDimensionGroup":{
"dimensionGroup":{
"range": {
"dimension":"ROWS",
"sheetId":0,
"startIndex":2,
"endIndex":5
},
"depth":0,
"collapsed":true
},
"fields":"*"
}
}],
"includeSpreadsheetInResponse":true}',
...
I'm not entirely sure what I am supposed to provide for "fields", the documentation for UpdateDimensionGroupRequest says it is supposed to be a string ("string ( FieldMask format)"), but the FieldMask definition itself shows the possibility of multiple paths, and doesn't tell me how they are supposed to be separated in a single string.
What am I doing wrong here?
The error message is actually instructing you that the dimensionGroup.depth value must be > 0:
If you call spreadsheets.get() on your sheet, and request only the DimensionGroup data, you'll note that your created group is actually at depth 1:
GET https://sheets.googleapis.com/v4/spreadsheets/{SSID}?fields=sheets(rowGroups)&key={API_KEY}
This makes sense, since the depth is (per API spec):
depth numberThe depth of the group, representing how many groups have a range that wholly contains the range of this group.
Note that any given particular DimensionGroup "wholly contains its own range" by definition.
If your goal is to change the status of the DimensionGroup, then you need to set its collapsed property:
{
"requests":
[
{
"updateDimensionGroup":
{
"dimensionGroup":
{
"range":
{
"sheetId": <your sheet id>,
"dimension": "ROWS",
"startIndex": 2,
"endIndex": 5
},
"collapsed": true,
"depth": 1
},
"fields": "collapsed"
}
}
]
}
For this particular Request, the only attribute you can set is collapsed - the other properties are used to identify the desired DimensionGroup to manipulate. Thus, specifying fields: "*" is equivalent to fields: "collapsed". This is not true for the majority of requests, so specifying fields: "*" and then omitting a non-required request parameter is interpreted as "Delete that missing parameter from the server's representation".
To change a DimensionGroup's depth, you must add or remove other DimensionGroups that encompass it.