awaisalvi / struts2-jquery

Automatically exported from code.google.com/p/struts2-jquery
0 stars 0 forks source link

datefmt option not available in plugin. #105

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a column with formatter as date
2. Set the formatoptions to be 
formatoptions="{srcformat:'d-m-Y', newformat:'d-m-Y'}"
3. Enter a date like: 25-12-2012 when adding a record or editing an 
existing record.

What is the expected output? What do you see instead?
The value should be accepted. 
However, the date entered is not accepted and an error:
Please, enter valid date value - Y-m-d

Which struts2 version?
2.1.8

Which struts2-jquery plugin version?
1.8.1

Please provide any additional information below.

I can't set the datefmt option to use dd-mm-YY. The plugin doesnt give me 
the option to do this when creating sj:gridColumn

So I'm using formatoptions to overwrite this already set value in the 
plugin. However it doesn't seem to work.

Even when I dont use the formatoptions for my column, when I edit the date 
it will only accept the format as Y-m-d.

Is this a bug?

Original issue reported on code.google.com by ramfrombo@gmail.com on 3 Mar 2010 at 10:39

GoogleCodeExporter commented 9 years ago
why has your srcformat and the newformat the same value?

the srcformat specify the date in your JSON result and newformat
is the date you want to see.

Original comment by johgep on 4 Mar 2010 at 6:39

GoogleCodeExporter commented 9 years ago
My server date is in the form dd-mm-yyyy(which is returned in my JSON result) & 
I 
want to display on screen dd-mm-yyyy. So that is why I put the srcformat the 
same as 
the newformat(in hind sight maybe this is redundant). If I dont put the 
formatoptions in my grid column, the date does display as per my JSON result. 
Which 
is good.

However, when I try to add a new record or edit an existing one, If I input my 
date 
as dd-mm-YYYY I get the error "Please, enter valid date value - Y-m-d".

What can I do in my gridColumn so that dd-mm-YYYY can be accepted as a valid 
date 
value?

Original comment by ramfrombo@gmail.com on 4 Mar 2010 at 12:09

GoogleCodeExporter commented 9 years ago
try it this way:

            <sj:gridColumn
                name="date"
                index="date"
                title="Date"
                formatter="date"
                formatoptions="{newformat : 'd.m.Y', srcformat : 'Y-m-d 
H:i:s'}"
                width="90"
            />

Original comment by johgep on 4 Mar 2010 at 12:42

GoogleCodeExporter commented 9 years ago
I tried your suggestion but I still cannot save any date other than in Y-m-d 
format.

With your suggestion the date is formatted on display of the row properly in 
d.m.Y.
However, when I modify the date (still in the d.m.Y format), I get the same 
error as 
mentioned before.

Is it possible that if the plugin had a datefmt option that we can set in a 
column, 
then this might override what is in jqgrid(Y-m-d) & work?

Original comment by ramfrombo@gmail.com on 4 Mar 2010 at 5:53

GoogleCodeExporter commented 9 years ago

Original comment by johgep on 22 Mar 2010 at 12:23

GoogleCodeExporter commented 9 years ago
has anyone got an example then of how I can use a column of type date to accept 
the 
format dd-mm-yyyy?

since my software is being sold in europe, it is imperative that I can use this.

Please help.
Thank you.

Original comment by ramfrombo@gmail.com on 23 Mar 2010 at 11:30

GoogleCodeExporter commented 9 years ago
This sample works great in my case.

            <sj:gridColumn
                name="processingDate"
                index="processingDate"
                title="Datum"
                formatter="date"
                formatoptions="{newformat : 'd.m.Y H:i', srcformat : 'Y-m-d 
H:i:s'}"
                sortable="true"
                width="90"
                search="true"
                searchoptions="{sopt:['eq','ne','lt','gt'], 
dataInit:datePick, attr:{title:'Verarbeitungsdatum'}}"
            />

srcformat is the date format from JSON Result, I think this should the same in 
your 
case.

newformat is the display format what i want.

Original comment by johgep on 24 Mar 2010 at 7:03

GoogleCodeExporter commented 9 years ago
I have tried your code exactly as you suggested and it does format the date for 
display as I want(dd.mm.yyyy).
However when I try to create a new record/edit the date and if I input the date 
in 
dd.mm.yyyy, when I submit I get an error saying that it must be in the format 
Y-m-d.

Do I need to have a specific function to convert date entered in dd.mm.yyyy to 
Y-m-d 
so that I dont get this jqgrid error message?

In your application, can you add a new date in this newformat?
 & submit ok to the server.

Original comment by ramfrombo@gmail.com on 24 Mar 2010 at 10:11

GoogleCodeExporter commented 9 years ago
This issue that I am facing, could this have anything to do with the locale 
settings 
that jquery uses? displaying works but not adding/editing... anyone with any 
help on 
this?

Original comment by ramfrombo@gmail.com on 26 Apr 2010 at 11:48

GoogleCodeExporter commented 9 years ago
I wonder is it an issue with the editoptions where I use this:

editoptions="{size: 10, maxlength: 10, dataInit: function(element) {
$(element).datepicker({dateFormat: 'dd-mm-yy'}) } }"  

editrules="{required:false, date:true}" 

Original comment by ramfrombo@gmail.com on 26 Apr 2010 at 11:51

GoogleCodeExporter commented 9 years ago
Hi Johannes

I believe that if the datefmt option is available for the column properties in 
the 
plugin, it will allow dates to be successfully saved in the format specified by 
the 
user.

Please see this link:
http://www.trirand.com/jqgridwiki/doku.php?id=wiki:colmodel_options

colmodel properties:

datefmt - Governs format of sorttype:date (when datetype is set to local) and 
editrules {date:true} fields. Determines the expected date format for that 
column. 
Uses a PHP-like date formatting. Currently ”/”, ”-”, and ”.” are 
supported as date 
separators. Valid formats are: 
y,Y,yyyy for four digits year 
YY, yy for two digits year 
m,mm for months 
ISO Date (Y-m-d)

Since we cannot set datefmt, it means that it will always use the ISO Date 
default 
of Y-m-d which explains why I cant edit a date to my own format of dd-mm-YYY.

Awaiting your opinion on this matter.
thanks

Original comment by ramfrombo@gmail.com on 27 Apr 2010 at 12:03

GoogleCodeExporter commented 9 years ago
Hello,
problem is maybe in different format options for gridColumn and datepicker?! 
I solved this problem, when I deleted formatter="date". Now it works good:
e.g.

<sjg:gridColumn name="birthday" index="birthday" title="Birthday"
 editable="true" edittype="text" editrules="{required:true, date:true}"
 editoptions="{dataInit:function(element){ $(element).datepicker({dateFormat:'d.m.yy'}) }}"
 formatoptions="{newformat:'d.m.Y'}"/>

Original comment by robert.s...@gmail.com on 21 Apr 2011 at 1:29

GoogleCodeExporter commented 9 years ago
I was also facing the same problem but it was resolved when changed the 
editrules="{required:true, date:true}" instead of editrules="{required:false, 
date:true}", but removing the formatter="date" will cause problems.
Hi johgep what is the correct way to make the changeyear true in the edit and 
add option ?
i have included $(element).datepicker({changeYear:'true'}); in the function but 
not working its showing the current month and for fields like date of birth its 
hard to navigate to a partricular year as it requires number of clicks.

Original comment by raji.san...@gmail.com on 4 Aug 2011 at 10:14

GoogleCodeExporter commented 9 years ago
Hi  i got the issue resolved.. it was because true was surrounded with single 
quotes, agn i could only get the years from 2000,but its all because i am new 
to this

Original comment by raji.san...@gmail.com on 4 Aug 2011 at 12:02