select2 sorter not receiving the additional parameters passed in data object - jquery-select2

And I'm passing some additional values in the options objects. The options object looks as follows Please note that these values are passed from PHP as the page loads not from an Ajax call. So I think I can't using processResult callback
{
"results": [
{
"id": 1,
"text": "Option 1",
"actual_id": "some_value"
},
{
"id": 2,
"text": "Option 2",
"actual_id": "some_value2"
}
],
"pagination": {
"more": true
}
}
This was working well until I decided to write a custom sorter function. I'm doing some processing with the actual_id after the item is selected. This issue is that the sorter function is not receiving the "actual_id" key and its value in its data parameter. So if enable the sorter, the after selection callback function is not getting the "actual_id" in its selected object. If I disable the sorter function selection callback function is working fine and is getting the "actual_id" in its selected object.

Related

Restassured: How Can we compare each element in Json array to one particular Same value in Java using Hemcrest Matchers, not using Foreach loop

Restassured: How Can we compare each element in Json array to one particular Same value in Java using Hemcrest Matchers, not using Foreach loop.
{
"id": 52352,
"name": "Great Apartments",
"floorplans": [
{
"id": 5342622,
"name": "THE STUDIO",
"fpCustomAmenities": [
{
"displaySequence": 2,
"amenityPartnerId": "gadasd",
"display": true,
"leased": true
},
{
"displaySequence": 13,
"amenityPartnerId": "sdfsfd",
"display": true,
"leased": true
}
]
},
{
"id": 4321020,
"name": "THE First Bed",
"fpCustomAmenities": [
{
"displaySequence": 4,
"amenityPartnerId": "gadasd",
"display": true,
"leased": true
},
{
"displaySequence": 15,
"amenityPartnerId": "hsfdsdf",
"display": true,
"leased": true
}
]
}
]
}
I want to compare that Leased=true for all the leased nodes at all the levels in the json response...
I have working code...
List<List<Boolean>> displayedvaluesfpStandardAmenities =
when().get(baseUrl + restUrl).
then().statusCode(200).log().ifError().
extract().body().jsonPath().getList("floorplans.fpCustomAmenities.display");
for (List<Boolean> displayedStandardList : displayedvaluesfpStandardAmenities) {
for (Boolean isDisplayedTrue : displayedStandardList) {
softAssert.assertTrue(isDisplayedTrue);
}
}
But the issue is I need the code to be in simple format using either Hemcrest Matchers or Restaussred Matchers and try simplistic way like Below, ( which is not working)
when().get(baseUrl + restUrl).
then().assertThat().body("floorplans.fpCustomAmenities.display",equalTo("true"));
The error I am getting is
java.lang.AssertionError: 1 expectation failed.
JSON path floorplans.fpCustomAmenities.display doesn't match.
Expected: true
Actual: <[[true, true], [true, true]]>
So what I need is the that all thes 'display' nodes in the json response where ever it is need to compared with "true", so that my test can Pass.
I have an alternate solution like mentioned above, but All I need is working solution using matchers.
Assuming fpCustomAmenities arrays are not empty, you can use the following solution;
when().get(baseUrl + restUrl).then()
.body("floorplans.findAll { it }.fpCustomAmenities" + // 1st line
".findAll { it }.leased.each{ a -> println a }" + // 2nd line
".grep{ it.contains(false) }.size()", equalTo(0)); // 3rd line
Here from the 1st line, we return each object in fpCustomAmenities array.
From the 2nd line we get boolean value of leased in each fpCustomAmenities object to a boolean array ([true, true]).
Each boolean array is printed from .each{ a -> println a }. I added it only to explain the answer. It is not relevant to the solution.
From 3rd line we check whether, if there is a false in each boolean array. grep() will return only the arrays which has a false. And then we get the filtered array count. Then we check whether it is equal to 0.
Check groovy documentation for more details.
Or
This solution does not use any Matchers. But this works.
String responseBody = when().get(baseUrl + restUrl).
then().extract().response().getBody().asPrettyString();
Assert.assertFalse(responseBody.contains("\"leased\": false"));

After adding arrays together, is there a way to know which elements came from which parent array?

Here's the JSON i'm working with:
{
"featured": [
{
"name": "Featured Show number 1",
"id": "123",
"slug": "featured-show-number-one",
"description": "This is an item description for show number 1"
},
{
"name": "Featured Show number 2",
"id": "456",
"slug": "featured-show-nubmer-tow",
"description": "This is an item description for show number 2"
}
],
"nonfeatured": [
{
"name": "Show number 3",
"id": "789",
"slug": "show-number-three",
"description": "This is an item description for show number 3"
},
{
"name": "Show number 4",
"id": "135",
"slug": "show-number-four",
"description": "This is an item description for show number 4"
}
]
}
What I am trying to figure out is after I parse this JSON using two data models, one for "Featured" and one for "Nonfeatured", looping through each show and adding it to an array, I need to add the arrays of shows together to create one array containing all the shows. However, I need to keep track of which shows are featured and which ones are non featured from the single array. Is there a way to do this?
The short answer to your specific question here is 'no'. The result of adding array A and array B (where both contain the same types) is A + B; there is no metadata providing any kind of source information.
But that is not to say that you couldn't accomplish the same thing by changing the model slightly. One option would be to add an extra boolean flag to the model called isFeatured or similar. Or you could 'future-proof' any work by using an enumeration of source lists containing featured, non-featured plus anything else you may require later.
To take the first example, an option would be to add the boolean field and then call code similar to below prior to 'summing' the arrays.
arrayA.forEach { $0.isFeatured = true }
arrayB.forEach { $0.isFeatured = false }
let arrayC = arrayA + arrayB
Then each element in the summed array will tell you its source list.

How to add content to table cell via google-docs-api request?

I want to add a content to a table cell in google doc, but the way described in the documentation doesn't work.
What is wrong with my request? When I provide 1 for index parameter of insertText request it just pastes text before table. When I provide 2 as value of index parameter I get an error: "Invalid requests[1].insertText: The insertion index must be inside the bounds of an existing paragraph. You can still create new paragraphs by inserting newlines."
{
"requests": [
{
"insertTable": {
"endOfSegmentLocation": {
"segmentId": ""
},
"columns": 1,
"rows": 1
}
},
{
"insertText": {
"location": {
"index": 1
},
"text": "Cell content"
}
}
]
}
I expect that text must be inserted into the only cell of the table.
You want to append a table (1 x 1) to the last body.
You want to insert a text to the 1st cell.
From your request body, I could understand like above. If my understanding is correct, how about this flow? I think that there might be several solutions. So please think of this as just one of them.
In the case that new table is appended to the last body ("segmentId": "" means that the table is appended to the last body.), at first, the start index of the table is required to be known. So how about the following flows?
Flow 1:
In this flow, it supposes that the index of last body is not known.
Append a table using the following request body.
{
"requests": [
{
"insertTable": {
"endOfSegmentLocation": {
"segmentId": ""
},
"columns": 1,
"rows": 1
}
}
]
}
Retrieve the start index of table using the following endpoint. At that time, you can also retrieve the start index of the cell.
GET https://docs.googleapis.com/v1/documents/{fileId}?fields=body(content(startIndex%2Ctable))
Insert the text to the cell. In this case, it supposes that the retrieved start index of the appended table is 10. The start index of the 1st cell is 14 (I think that the start index of the 1st cell can be retrieved by start index of table + 4.). In this case, the request body for inserting the text to the cell is as follows.
{
"requests": [
{
"insertText":
{
"location":
{
"index": 14
},
"text": "Cell content"
}
}
]
}
Flow 2:
In this flow, it supposes that the index of last body is known. For example, when the table is appended to the new Document, you can create the table with the text using the following request body. In this case, the start index of the table and the cell are 1 and 5, respectively.
{
"requests": [
{
"insertTable":
{
"endOfSegmentLocation":
{
"segmentId": ""
},
"columns": 1,
"rows": 1
}
},
{
"insertText":
{
"location":
{
"index": 5
},
"text": "Cell content"
}
}
]
}
References:
Inserting or deleting table rows
Thread: Insert table in Google Docs API Python
If I misunderstood your question and this was not the direction you want, I apologize.
This is a follow up to the answers posted already. #ANewb hinted the the flow ends after the 5th cell. Ensure the values/entries in the payload aren't empty strings. For anyone encountering the same challenge, you can try using tenary conditions - for php $value == "" ? "N/A : $value;, for js let value = checkValue == "" ? "N?A": checkValue;

Unable to set dynamic dropdown value in Zapier CLI trigger

I have my app in Zapier CLI. I have created a trigger to set dropdown values for a particular action step during zap creation.
The data comes like this :
{ "data": {
"account_status": {
"field_name": "account_status",
"field_label": "Status",
"field_type": "list",
"field_length": "50",
"field_items": "Active|Inactive|444|Closed",
"required": "0",
"related_module": "",
"related_field_name": "",
"join_table": "",
"join_lhs_field_name": "",
"join_rhs_field_name": "",
"related_data_field": ""
},
}
}
Here is my code:
Now I am trying to set the data for the dynamic dropdown using field_items value from the above result like this:
return responsePromise
.then(response => JSON.parse(response.content ) )
.then(data => {
const account_status_list = data.data.account_status.field_items;
const account_status_arr = account_status_list.split("|");
return account_status_arr.map(function(e){
e.id = e
return e
})
})
my input field for the dynamic dropdown trigger is:
{
key: 'account_status',
label:'Account Status',
required: false,
dynamic: 'account_status.account_dropdown.id'
}
On clicking the dropdown I get this error
Can anyone suggest where I am going wrong or what may I do to resolve this ?
David here, from the Zapier Platform team.
The issue is that Zapier expects an array of objects and you're returning an array of strings. It seems like you're trying to make an id field in your code snippet, but calling "Active".id = "Active" won't make an object.
Instead, you should change your map function to be something like the following:
return account_status_arr.map(function(e){
return {id: e}
})
The other thing you'll probably need to tweak is how your dynamic dropdown is set up. It's a period-separated string that follows the format trigger_key.id_key.label_key. The id and label can be the same key; it really depends on what data you need to send to the API (the label is just for show, the id is what's actually sent). In the dynamic field, you'll have a dyanmic property that'll be account_status.id.id.
There are docs here.

Swagger query parameter template

I have on query parameter which is little bit complex and i have my own syntax to make that value. Its has more then one variable to make one complete string value.
Let suppose name of parameter is index which has row and column like to make this value 20:30
index = { row: 20, col:30 }
index2 = { row: 20, col:30, chr: 15 }
Now i wanted to make it as
example.com?index=20:30
example.com?index2=20:30:15
Can someone tell me how can i define this in swagger ?
Thank you.
Make your swagger parameter a string and in your code behind handle the splitting into multiple variables...
I do exactly that here:
http://turoapi.azurewebsites.net/swagger/ui/index#/Echo/Echo_Get
"parameters": [
{
"name": "location",
"in": "query",
"description": "SoFL= 26.16,-80.20",
"required": true,
"type": "string"
},
That location is (Latitude,Longitude) and I split it with a C# TypeConverter
...and the request looks like:
http://turoapi.azurewebsites.net/api/Echo?location=26.16,-80.20
The code for that WebApi is here:
https://github.com/heldersepu/TuroApi

Resources