I am trying to write a RAML data type fragment that would strictly define how selectedDate should be accepted
#%RAML 1.0 DataType
properties:
selectedDate?:
type: array | date-only
example: ["2020-08-05", "2020-08-06"]
example:
selectedDate: "2020-08-05"
User can send the date in string as date-only or an array, as shown in the two examples above.
But I need to allow the date in a date-only format, even when its sent in an array. But here array allows strings as well that are not dates.
I feel I am not explaining it well. Any help is appreciated.
You can define the array to be an array based on a type for the elements by adding the [] suffix to the type: date-only[]. You can also encapsulate that definition into a new type.
Related
The full code can be found here:
https://codesandbox.io/s/peaceful-allen-sn6os?file=/src/App.tsx
What I am trying to do is render a table using react-table and would like to dynamically generate the columns array containing the Headers, accessors and Cell attributes and set them dynamically based on the types of values present within a given data set.
In the code sample above, for example, the data is an array of todos and I am trying to set the Column Headers & Cell Values text to align right if their type is a number by checking the type of cell values present in the data set.
However, I am having problems getting to render the Headers attribute.
The following is mentioned in the docs and I believe I am returning valid JSX, but I may be doing something wrong here and any help would be greatly appreciated in resolving this issue! Thank you.
https://react-table.tanstack.com/docs/api/useTable
Header: String | Function | React.Component => JSX
- Optional
- Defaults to () => null
- Receives the table instance and column model as props
- Must either be a string or return valid JSX
- If a function/component is passed, it will be used for formatting the header value, eg. You can use a Header function to dynamically format the header using any table or column state.
The input box is initialized properly but it is not generating any suggestions. Can any one point out what I am doing wrong? Here is the code.
Update
I have investigated the issue. The problem is in the line:
types: ['(cities)', '(regions)']
when I specify only one type types: ['(cities)'] no matter region or cities it works. But two types are not working together. Although the documentation clearly says that types are Array of strings and valid values are 'establishment', 'geocode', '(regions)' and '(cities)'
As mentioned in the documentation:
"types, which can either specify one of two explicit types or one of two type collections."
This means that the types array only supports one parameter.
If you think it would be a useful feature to support more than one parameter or a mixture of explicit types and collections, please file a Places API - Feature Request.
As Chris mentioned, there is currently no way to get results for multiple place types.
However, you can call the API twice with different place types and populate a map (or whatever you're building) with both types. For example:
var request1 = {
location: event.latLng,
radius: 8047,
types: ['cafe'],
};
var request2 = {
location: event.latLng,
radius: 8047,
types: ['library'],
};
There are no results of type (cities)' or '(regions)'. If I change the types array to ['establishment'], I get results.
Working example
If you use only one type, it works:
Example
I have a list of progress notes (collection of simple objects), on this screenshot, first three were in the model, and the last one was added to the model using push command:
In HTML this presenttion is defined like this:
<div ng-repeat="item in vm.data.ProgressNotes|orderBy:'-Date'">
reversed sort by Date, most recent are on top.
New object is added to the collection like this:
data.ProgressNotes.push({
Note: progressNote,
UserName: ctx$.uName,
Date: new Date()
});
Sample model fragment of vm.data.ProgressNotes:
Question: Why new item is not displayed on top, orderBy doesnt work for items added using push ??
You have different data type for the Date in the note object. In the model, it is represented as string but when you push a new note to the array, the new note has the Date as date type Date: new Date(). When angular does order by with different data types, the comparison is done within the values in the same types and then compares the types themselves alphabetically.
I created a plunker to demonstrate this behavior.
https://plnkr.co/edit/qiKHuRWqI7YR1gJKMvOL?p=preview
As others have mentioned, the type of Date property in the sample data is string. You will have to modify the sample data to make the Date properties of type Date.
You can do something like this:
ProgressNotes.forEach(function(progress_note){
progress_note.Date = new Date(progress_note.Date);
});
So now the sample data will also have Date property of type Date.
I'm using ng-tags input, and the data I get after populating a line is an array of object, each with one 'text' string field like so
[{"text":"egon"},{"text":"peter"},{"text":"raymond"},{"text":"winston"}]
Is there a way to store the data as an array of strings instead? like
["egon", "peter", "raymond", "winston"]
ngTagsInput only works with arrays of objects. You can easily extract an array of strings out of an array of objects, though:
$scope.tagsString = $scope.tags.map(function(tag) { return tag.text; });
Update
It took some time, but ngTagsInput offers now basic support for array of strings. Starting in v3.2.0, the following is possible:
<tags-input ng-model="tags" use-strings="true"></tags-input>
Plunker
Better late than never, I guess.
Custom Date and Time Format Strings on MSDN
Link above seems to use {0:MM/dd/yy H:mm:ss zzz} a lot.
I understand all the letters and formatting options but I can't seem to find what the preceding "0:" is for?
The {0} is a composite formatting placeholder, meaning the first item in the format value list. For details, see this MSDN article, in particular, the section called "Composite Formatting" near the bottom, or the larger article specifically about Composite Formatting. But, to summarize:
In .NET there are two kinds of string formatting you can do: ToString formatting and composite formatting. Both of them use the same custom format string syntax.
When you have a single object, like a DateTime variable, and you call DateTime.ToString() on that object, you can pass a formatting string and it will apply to that object, and format it according to your pattern. But if you have more than one object and you want to build a complex string that includes their values, you instead call String.Format. That function expects a "format string" that contains placeholders where the variable bits go, which look like {0:g} or {5:MM/dd/yy} or something. The remainder of the parameters to String.Format is a list of variables. The {0} placeholder is the first variable, {5} is the 6th, etc.