Kendo UI - Angular - Formatting a date column - kendo-ui

I'm trying a simple thing as displaying a date column in a kendo ui grid in Angular using the following:
<kendo-grid-column field="date" title="Date" type="date" format="{0:d}"></kendo-grid-column>
However the result is:
'2017-04-30T09:00:00'

I guess you are using the data received from your backend. It that case your should convert your date field to Date type manually.
return this.http.get("url")
.map((res: Response) => {
let result = res.json();
result.forEach((x) => {
x.dateField= new Date(x.dateField);
});
return result;
})

Use the following in place of your format code: format="{0:dd/MM/yyyy}". You have to specify which format you wish to use

Related

Formatting number in Eloquent query or Yarja Datatables

I am writing a searchable table which includes the area and population. Here is the basic query:
public function getCountryData()
{
$co = DB::table('countries')->leftJoin('country_detail','country_detail.country_id','=','countries.id')->addSelect(['countries.id','countries.name','country_detail.capital','country_detail.area','country_detail.iso3','country_detail.population','country_detail.currencyName','country_detail.phone','country_detail.continent'])->get();
return Datatables::of($co)
->addColumn('action', function($co){
$btn = '<div style="float:right">
'.getEditIcon().''.getBinoculars().'';
return $btn;
}) ->rawColumns(['action'])
->make(true);
}
All this works fine in my view except that the population field, for example, returns something like 29121286 and of course I want to format it so it is 29,121,286.
Can this be done in the query or something in Datatables itself?
Instead of formatting the number on client side using javascript, I suggest using php's number_format function to format your number.
return Datatables::editColumn('population', function($item) {
return number_format($item->population);
});
For more help on formatting numbers, see https://www.php.net/manual/en/function.number-format.php
Thanks to Navok on Laracasts here is the answer.
Firstly you need a javascript function to convert the string to a number, properly formatted.
function formatNumber(num) {
return num.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,')
}
I have added this in a file called misc.js (so I can have other things) which I call from the layouts.app so it is available system wide.
This can be found at https://blog.abelotech.com/posts/number-currency-formatting-javascript/.
Then within the datatables declaration on your page add
createdRow: function (row, data, dataIndex) {
if (data.population !== undefined) {
// 4 here is the cell number, it starts from 0 where this number should appear
$(row).find('td:eq(4)').html(formatNumber(data.population));
}
},
I hope this is of value.

Redux Form - Not able to type anything in input

Hi I have upgraded to redux-form version 6.0.0 recently. And I am facing an issue like I am not able to type anything in the text field.
P.S I am also using Reactintl. I am using compose to aggregate connect, reduxform and intl decorator
Here is my code
Pastebin
If I understand correctly, then starting with v6 you should provide extra onBlur and onChange methods for the input in order to update its state. For your stateless component renderInput it could be done like this:
const renderInput = (field) => {
const onBlur = () => {
field.input.onBlur(field.input.value);
};
const onChange = (inputValue) => {
field.input.onChange(inputValue ? inputValue : '')
};
return <input {...field.input} onBlur={onBlur} onChange={onChange}
[...other options omitted for readability] />
}

How can we show error message on form validation on joomla 2.5 in the same way as email validation with a tooltip like alert?

How can we show error message on form validation on joomla 2.5 in the same way as email validation etc? with the tool tip?
I have included
JHtml::_('behavior.formvalidation');
JHtml::_('behavior.tooltip');
and I have a script
$(document).ready(function () {
var msg = new Array();
document.formvalidator.setHandler('phone', function (value) { return (value != '123'); } );
});
and My input filed is like
<input name="jform[contact_phone]" type="text" id="jform_contact_phone" class='validate-phone'/>
I am getting the tooltip for email field validation and required filed validation, but I can not include numeric validation and I could not implement a tooltip message for my custom phone number field.
I am using joomla 2.5
Please check here for custom validation
http://docs.joomla.org/Client-side_form_validation
You have to add like below:
window.addEvent('domready', function(){
document.formvalidator.setHandler('birth', function(value) {
regex=/^\d{4}-\d{2}-\d{2}$/;
return regex.test(value);
});
});
If its only for numeric click below URL and try this also:
Validate phone number in joomla 2.5

JQuery datePicker not working for dynamically created input element

I am trying to integrate the jquery datepicker to an input field which i am creating dynamically using script..
my script is like...
function getDate(id)
{
$('.pop-up-link').show();
$.ajax({
url : 'gettartDate.jav',
data : 'Id='+id,
success : function(dateStr)
{
var htmlStr = 'Start Date : <input type="text" class="datepicker" id="startDateId" value="'+dateStr.StartDate+'"/>';
$(".pop-info").html(htmlString);
$('.datepicker').datepicker({ dateFormat: 'yy-mm-dd', changeMonth: true, changeYear: true});
}
}
I am calling this script when i need to edit the date in database and to add new entry to database. When i need to add new entry, im setting id as 0 and returning a blank string..
Now my problem. the datepicker works perfectly for edit functionality.. But when i add a new entry, the datepicker ui comes.. But the date is not updating to that input field. Again, when i put an alert to display selected date,i noticed that only date is changing.. The year and month is not changing, even when i change it
It could be down to the fact you are dynamically adding the datepicker with the same ID's, i was having the same issue with dynamically created datepickers. if there was anyway you could take out the Id attr and use the Name attr it should work.
so you should have the following
var htmlStr = 'Start Date : <input type="text" class="datepicker" name="startDateId" value="'+dateStr.StartDate+'"/>';
Try using the refresh method on .datepicker like so:
$( ".datepicker" ).datepicker( "refresh" );

How to get values of jQuery Tags Input plugin

I use this jQuery Tags Input plugin:
jQuery Tags Input
but I can't get the values on my php file.
If you are trying to get the individual values using jQuery you can use:
(This is assuming the text input you made into a tag input has an id of "keywords")
$('#keywords').tagsInput({
'height':'auto',
'width':'350px',
'defaultText':'',
'delimiter': '|'
});
/*The delimiter option above overrides the default comma delimiter in the plugin allowing commas in tags if you prefer that...*/
var $keywords = $("#keywords").siblings(".tagsinput").children(".tag");
var tags = [];
for (var i = $keywords.length; i--;) {
tags.push($($keywords[i]).text().substring(0, $($keywords[i]).text().length - 1).trim());
}
/*Then if you only want the unique tags entered:*/
var uniqueTags = $.unique(tags);
alert(uniqueTags.toSource());
To get the list of emails from:
<input type="text" name="to_addresses" class="to_addresses" data-role="tagsinput" >
I use:
$emails = []
$.map($(".tagsinput span span"),function(e,i){
$emails.push($(e).text().trim());
})
Works for me, thought I'd share it.
$("#btn").click(function () {
var $tagWord = $("#tags_2").siblings(".tagsinput").children(".tag");
var tags = [];
for (var i = $tagWord.length; i--; ) {
tags.push($($tagWord[i]).text().substring(0, $($tagWord[i]).text().length - 1).trim());
}
/*Then if you only want the unique tags entered:*/
var uqTags = $.unique(tags);
alert(uqTags.toSource());
});
using jquery you can do it in one line:
$.map($('.tag span'),function(e,i){return $(e).text().trim();})
$("input").tagsinput('items')
["Amsterdam","Washington","Sydney","Beijing","Cairo"]
$("input").val()
"Amsterdam,Washington,Sydney,Beijing,Cairo"
can you provide an example of what is POSTed? you can do so by pointing your form to go to api.fatherstorm.com?query and copying the json data that it gives you
it change the hidden input value, and will post the data when you click submit , you can test it by a simple php script. print_r($_POST) to see it.
Based on sagivo answer you can write a function like this :
function getKeywords() {
return $.map($('.tag span'),function(e,i){
return $(e).text().trim();
});
}
That will return an array of keywords present in the input.
Like this [ "there", "it", "is" ]

Resources