I was wondering if it would be possible to format strings (in this case the string displayed in the field OrderDate) using the "attributes:{}" thing ( I do not know how I should call that. A tag? A property?)
NOTE: This is inside a kendogrid which gets JSON data from a remote server.
NOTE 2 : The attributes:{style:text-align:center;"} works just fine.
field : "OrderDate",
title : "Orderdatum",
attributes:{style:"text-align:center;"},
width : 170,
If there is anything else that I need to provide you with, do say so.
Thanks in advance everyone! And if this looks like I haven't searched or something, then I can assure you I have.
I thought this might help people get an idea of how it looks. What I want to achieve in my case is that IF the data is 3-3-2009 (the selected cell/row) that it shows as 03-03-2009. Is it possible to achieve it using attributes ?
Again, thanks in advance.
Edit 2:
This link tells me it is not possible to do it in CSS3. So my guess now is that I accidently have created a duplicate question. So let me rephrase my quesion: How can I format the string, not necessarily using attributes, so it looks how I explained I want it to look?
Edit 3:
I was supposed to include this.
As you can see what I get is a string and not a number.
schema: {
type : "json",
data : "SalesOrders.SalesOrder",
model: {
fields: {
OrderNo : {type: "string"},
OrderDate : {type: "string"},
DeliveryWeek : {type: "number"},
OrderTotal : {type: "number"},
OBJECTID : {type: "number"},
},
Yet again, thanks for your time to read my question.
In this scenario, you are unable to format the string using CSS3 (Like totally impossibru...)
Therefore, you need to format your JSON object once its loaded, before its passed into the grid for display.
Formatting of data (This link give you some idea on how you format the datasource)
http://www.telerik.com/forums/datasource-number-format
Formatting dates (This link give you idea on how to format dates)
http://docs.telerik.com/kendo-ui/getting-started/framework/globalization/dateformatting
If you are not comfortable with kendo formatting of dates (Yes, I hate it), you can use the sweet momentJS
http://momentjs.com/
BTW (EDITED)
Kendo grid date column not formatting
this is a quicker and cleaner way of using "template" attribute for formatting
We can combine the functionality (described in the following Kendo UI documentation) to reformat the date during the DataBound event:
http://docs.telerik.com/kendo-ui/getting-started/framework/globalization/dateformatting
http://docs.telerik.com/kendo-ui/api/web/grid#events-dataBound
[update]
Here's some generic code to convey the idea:
<div id="grid"></div>
<script>
$("#grid").kendoGrid({
columns: [
{ field: "name" },
{ field: "age" }
],
dataSource: [
{ name: "Jane Doe", age: 30 },
{ name: "John Doe", age: 33 }
],
dataBound: function(e) {
console.log("put your Date conversion logic here in the dataBound event");
}
});
Related
Edit for clarity: There are no error messages, it simply returns an empty list if the input string is from the context.arguments, suggesting that it simply isn't getting the input variable out on the query tester (setting it up incorrectly brings up that famous typing error of course). I've also made this into a pipeline with the exact same result. Looking around, people suggest making an intermediate object, but surely I'm just getting my input variables out wrong somehow.
I'm working on a project in AWS Appsync using DynamoDB and I've run into a problem with the context.arguments input.
Basically the code all works if I hardcode the string for the book id into the query (full context to follow), but if I use the context.arguments, it simply refuses to work properly, returning an empty array for the "spines".
I have the following types in my schema:
type Book {
id: ID!
title: String
spines: [Spine]
}
type Spine {
id: ID!
name: String
bookId: ID!
}
I use the following query:
type Query {
getBook(id: ID!): Book
query getBook($bookId: ID!){
getBook(id: $bookId){
title
id
spines {
name
bookId
}
}
}
With the following input (assume this is a relevant guid):
{
"bookId": "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
}
And this resolver for the spines object:
{
"version" : "2017-02-28",
"operation" : "Query",
"index" : "bookId-index",
"query" : {
"expression": "#bookId = :bookId",
"expressionNames" : {
"#bookId" : "bookId"
},
"expressionValues" : {
":bookId" : { "S" : "${context.arguments.id}" }
}
}
}
}
I made sure my data set contained false positives too (spines for other books) so that I know when my query brings back the correct data.
This works if I hardcode a guid as string instead of using context.arguments, and gets exactly what I'm looking for for each book guid.
For example, replacing the expression values with this works perfectly:
"expressionValues" : {
":bookId" : { "S" : "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" }
}
Why does "${context.arguments.id}" not get the input variable here the same way as it seems to in other queries?
Thanks to #IonutTrestian for pointing me in the right direction.
$ctx.args was empty, but I decided to go up the chain to see what was in the entire context, so $util.error($util.toJson($ctx)).
The json object I found included a little object called "Source", which contained the query return for the Book object.
Long story short, $ctx.source.id when applied to my query worked a charm.
I also know a bit more about debugging DynamoDB resolvers in case I encounter problems like this in future. Thank you so much!
Hello good people of the stack!
I am working on a react-redux application and I am trying to update a property on a deeply nested structure in my reducer. The data structure is as follows and I want to update the text property:
state = {
assessment: {
requirements: [
questions: [
{
text
}
]
]
}
}
so I have tried the following:
// reducer code...
return {
...state,
[assessmentId]: {
...state[assessmentId],
requirements: [
...state[assessmentId].requirements,
[requirementId]: [
...state[assessmentId].requirements[requirementsId],
questions: [
...state[assessmentId].requirements[requirementsId].questions,
[questionId]: {
text: action.payload.response.text
},
],
] ,
],
},
};
This is more pseudo code than actual code to remove complexity.
I do not see any change in redux dev tools so I am wondering if I have made a mistake the way I get the nested objects and array elements.
I was also curious about using combine reducers here. I asked a colleague and they suggested to use that but I am unsure how you would take that approach here. As always, any help is appreciated.
I recommend immer for deep state changes in your reducers.
It adds a little weight to your bundle, and you'll get better performance from using the spread operator, but if you can live with that it'll make your code easier to read and write.
import produce from "immer";
// reducer code...
return produce(state, draft => {
draft[assessmentId].requirements[requirementsId].questions[questionsIndex].text = action.payload.response.text;
});
I'd say your issue stems from questions being an array which will take a little more work to keep straight than object based state.
As it is you appear to be trying to set the question value as if questions was an object. Maybe you just need to drop the [questionId] syntax, eg
questions: [
...state[assessmentId].requirements[requirementsId].questions,
{ text: action.payload.response.text },
],
This will set the text object as a new item on the end of the array though.
Depending on what you need to do (ie what already exists in the array and whether you are trying to add or update) you'll want to have a read of:
https://redux.js.org/recipes/structuring-reducers/immutable-update-patterns#inserting-and-removing-items-in-arrays
https://redux.js.org/recipes/structuring-reducers/immutable-update-patterns#updating-an-item-in-an-array
I'm using autoform with simple schema and collection2. In my form I collect a phone number. Phone numbers where I live start with a 0. When it saves to the database the 0 is removed. How can I stop this from happening?
phone: {
type: Number,
optional: true,
autoform: {
afFieldInput: {
type: "tel"
}
}
}
Numbers are stored without a leading-zero by definition - 0123 is not a valid number. You either need to add the leading zeroes when you get data out, or store the value as a string.
Save it as a string instead type: String or format it with a leading zero whenever you display it on screen. The latter is harder if you are also storing numbers from other locales and you don't know what format they are using.
use a string and add a regex validator on it
phone: {
type: String,
regEx: /^0{1}\d{10}$/, // or something like this
}
Thanks for all the help. FYI to those who might have a similar problem, see the code below. #corvid suggested using regEx and a quick google showed a solution for Australian numbers. It seems to work well. Thanks again everyone!
Link for the regEx soltuion
phone: {
type: String,
regEx: /^\({0,1}((0|\+61)(2|4|3|7|8)){0,1}\){0,1}(\ |-){0,1}[0-9]{2}(\ |-){0,1}[0-9]{2}(\ |-){0,1}[0-9]{1}(\ |-){0,1}[0-9]{3}$/,
optional: true,
autoform: {
afFieldInput: {
type: "tel"
}
}
},
I've been struggling with this for a couple of hours and I can't find a good solution so maybe someone can shed a light on this.
I have a simple schema like this:
var groupschema = new SimpleSchema({
name: {
label: 'Name',
type: String
},
description: {
label: 'Description',
type: String
}
}
And I have another one:
var itemschema = new SimpleSchema({
name: {
label: 'Type:',
type: String
},
details: {
label: 'Details',
type: String
},
group: [groupschema] // <--- this is my main interest
}
If I use the above code sample AutoForm will generate an "inner form" which is quite cool actually for some puporse (e.g. for a contact to have an array of adresses or phone numbers) but for me I would like a drop-down select with the name of the group and when I click on the Insert/Update button (depending on the current form) I would like to add the whole group document to the inserted/updated item document as a subdocument.
Something like this will be inserted to the mongodb:
{
_id: the generated mongoid,
name: "This is a type",
details: "There are some thing to know about this type",
group:{
name: "Cool group",
description: "This is a really cool group"
}
}
The actual documents are far more complicated the above example is just an oversimplified version.
I've stopped writing this question yesterday and tried to do my own version.
My - half baked - solution is:
introducing a new field in the schema named groupselect (type string, autoform type: select)
populate it's contents with a Collection.find().map() lookup
groupselect: {
type: String,
label: 'Group',
optional: true,
blackbox: true,
autoform:{
type: "select",
options : function() {
return Issuegroup.find().map(function (c) {
return {label: c.name , value: c._id};
});
}
}
},
using autoform hooks before insert I assign the subdocument to the real fiel group = Group.find({_id:doc.groupselect}) and I remove the helper field from the doc
using the same technique in the before update hook also for an update form
The problem I seem to be unable to solve in a clean way is to set the default value of the helper field 'groupselect' when the update form displays. I've tried the docToForm hooks but no luck.
Isn't this somehow a very common problem? I imagine there has to be a proper solution for this so I bet that I am missing something very obvious and hopefully someone will point it out for me.
Thanks
I have a Mongo collection that looks similar to the below example, I am using meteor-publish-composite, https://atmospherejs.com/reywood/publish-composite to publish documents to the client. I know with Mongo I can do the following to return specific items within the authors array.
db.books.find({"authors.authorSlug": "author-1}, {authors: {$elemMatch: { authorSlug: "author-1"}});
When I try to achieve the same thing using meteor-publish-composite, this does not seem to work as it returns the entire the authors' array, my code is as below.
Books.find({"authors.authorSlug": slug}, {authors: {$elemMatch:{authorSlug: slug}}});
Is this even possible to achieve with publish-composite?
{
"title" : "Book1",
"authors" : [
{
"name" : "Author 1",
"authorSlug": "author-1"
},
{
"name" : "Author 2",
"slug" : "author-2"
},
],
"slug" : "book1"
}
You only use publish-composite when you are trying to join 2 or more related collections into a single reactive subscription. You simply need a standard publish/subscribe for your collection - and you say you have working code so I don't see what your problem is! Or are you trying to get at your books data in addition to other data around it?