The only downside with that is that you'll be creating an additional preOpen event handler on each xhr trigger. The way to avoid that would be to change line 4 to be
editor.off('preOpen').on('preOpen', function (e, mode, action) {
Thank you Colin!
Colin, tell me something. What is the simplest way, with less code for me to format an input in the editor as DD / MM / YYYY date without using the moment of your example, because with those libraries I have errors.
I just need to leave the input as DD / MM / YYYY and write it correctly to the BD.
I'm having a hard time working with dates.
In my database, date_x is set to date (2020-06-17)
In the form editor, I need it to appear as 6/17/2020, both in edit and create.
I don't know how to solve it.
Colin said to use displayFormat, but I must have done it wrong.
What you'll need to define is the displayFormat for how you want it displayed, so for you, that'll 'M/D/YYYY'. Then, you'll need to define how it gets transmitted with wireFormat, so that will be 'YYYY-DD-MM`.
Good morning Colin. So let's continue here, better right? I just can't delete the new one I opened yesterday.
So, I'll detail:
In my BD table, a clipacdatnas field is defined as date, and the test I'm doing the date is like 2020-06-17 in my BD, which is the correct format.
In the editor it is defined as:
However, when you open the editor, it gets like a date nothing to do, like, thu, 26 november 2025.
I am not able to use the correct function for the date in the editor to appear as 17/06/2020 and if I enter the date 17/06/2020 in a new record in the editor, it will write correctly in the bd.
If I use datetime on the type, it just crashes. When I click to open the editor, it doesn't even do anything, the screen freezes. With type date it doesn't crash.
Am I required to use datetime !?
Look, I'm leaving to format a single date input! Sir !
Nothing Kevin, he doesn't have any errors on the console, he just crashes!
I'm thinking of leaving the field in the bd as a date.
The input leave as text. Then in create it shows right 18/06/2020, but when I edit it it shows 2020-06-18
Well, let's go.
I have and should use it this way.
{
label: "DATE OF BIRTH:",
name: "clipacdatnas",
type: 'date',
def: function () {return new Date (); },
dateFormat: 'dd / mm / yy',
},
When I use create, it formats the perfect date 18/06/2020.
When I use the edit, it brings me a totally wrong date: 06/12/2025.
In my bd it's like 2020-06-18, in json it's like 2020-06-18.
How do I get the correct date in edit mode?
And, as in the time of recording, to correctly record the date in the bd in this case?
I can't find a solution for that. Honestly, the complicated business saw it!
Could you give me a link to the page that is crashing when the date picker for datetime is shown please? That shouldn't be happening, and I'm not aware of any other reports matching that, so I'd like to debug it.
If you have to use jQuery UI date picker, you'll need to change the date format in the JSON. It expects only a single format - I don't think it will translate between a wire format and what is displayed (although you could ask their support channels).
Normally a get formatter would be used on the server-side for it. However, as I say, the datetime input should work and if it isn't it needs to be resolved.
Good Morning. Could someone help me or go through a path that really resolves this issue?
I'll explain again in detail.
My bd date is by default mysql YYYY-MM-DD
I need to show it on the editor's screen in DD / MM / YYYY format. This I am already managing using:
{
label: "DATE OF BIRTH:",
name: "clipacdatnas",
type: 'date',
def: function () {return new Date (); },
dateFormat: 'dd / mm / yy',
},
However, I need that, when editing, it shows the date of the bd, converted to this format and, when I click save in the edit, it will save in the YYYY-MM-DD format.
Can someone for God's sake help me?
See what happens.
The instant I edit, I record a DD / MM / YYY date (12/12/2020)
and I open the edit again, it shows me a totally wrong date. I need to refresh the page to open the editor and it will show the correct date.
I don't have Alan, I'm testing everything locally.
Look, I'm going to detail it entirely.
First:
In the editor I use:
{
label: "DATE OF BIRTH:",
name: "clipacdatnas",
type: 'date',
def: function () {return new Date (); },
dateFormat: 'dd / mm / yy',
},
My json is already returning DD / MM / YYYY.
Second:
I'm using in the editor:
Field :: inst ('clipacdatnas') -> getFormatter (Format :: dateSqlToFormat ("d / m / Y")),
Field :: inst ('clipacdatnas') -> setFormatter (Format :: dateFormatToSql ("d / m / Y")),
In my comic, I have a date (YYYY-MM-DD = 2020-06-19)
When I open the editor, it shows the right date 19/06/2020.
I change the date to 20/06/2020 and record.
I open the editor again and a date appears nothing to do. I need to refresh the screen, open the editor again to show the right date.
But Alan, the recording is working. I don't think you understand what I tried to explain.
When I edit the date, and open the editor again afterwards, the date shows a totally wrong date. I need to refresh the page and open the editor again for the date to show correctly.
It is a lot of back, a lot for a simple date formatting in this system.
There would be no need for so much work, so much code for a simple input date !!!!!
Sir, I am leaving this .... more than 3 days in it and no effective solution !!!!
Can you help me with this, please ????
That way it is not worth purchasing this tool .... It is soooo much work for a single little thing !!!!!
Every hour is a problem!
Blank date that looks like 1969-12-31, date that doesn't work when editing, display, anyway .... Sir !!!!!
Look at the thing ...
For me to be able to sort a date column, I have to keep using separate JS, the datatable just doesn't do it!
How many seams do we have to make to run a little business that should be simple!
Unless someone shows me and convinces me that I don't need it all.
Look, hard to see .... Now I understand you don't answer me anymore!
Replies
I had to put the second function inside the first one. There it worked. But ..... Is that correct !?
table_CP.on ('xhr', function () {
var json = table_CP.ajax.json ();
var ultcod = json.data [0] .ultcod;
editor.on ('preOpen', function (e, mode, action) {
if (action === 'create') {
editor.set ('clipaccod', ultcod);
}
});
});
The only downside with that is that you'll be creating an additional
preOpen
event handler on eachxhr
trigger. The way to avoid that would be to change line 4 to beColin
Thank you Colin!
Colin, tell me something. What is the simplest way, with less code for me to format an input in the editor as DD / MM / YYYY date without using the moment of your example, because with those libraries I have errors.
I just need to leave the input as DD / MM / YYYY and write it correctly to the BD.
The best way is to set
displayFormat
fordatetime
, as that allows you to display it differently to how it is sent to the server,Colin
Thank you very much Colin and sorry for the delay.
God bless everything there!
I'm having a hard time working with dates.
In my database, date_x is set to date (2020-06-17)
In the form editor, I need it to appear as 6/17/2020, both in edit and create.
I don't know how to solve it.
Colin said to use displayFormat, but I must have done it wrong.
What you'll need to define is the
displayFormat
for how you want it displayed, so for you, that'll 'M/D/YYYY'. Then, you'll need to define how it gets transmitted withwireFormat
, so that will be 'YYYY-DD-MM`.Hopefully that will do the trick,
Colin
Good morning Colin. So let's continue here, better right? I just can't delete the new one I opened yesterday.
So, I'll detail:
In my BD table, a clipacdatnas field is defined as date, and the test I'm doing the date is like 2020-06-17 in my BD, which is the correct format.
In the editor it is defined as:
However, when you open the editor, it gets like a date nothing to do, like, thu, 26 november 2025.
I am not able to use the correct function for the date in the editor to appear as 17/06/2020 and if I enter the date 17/06/2020 in a new record in the editor, it will write correctly in the bd.
As I said, use
datetime
, with the options I suggested - see example here.Colin
If I use datetime on the type, it just crashes. When I click to open the editor, it doesn't even do anything, the screen freezes. With type date it doesn't crash.
Am I required to use datetime !?
Look, I'm leaving to format a single date input! Sir !
Do you get errors in your browser's console?
Kevin
Nothing Kevin, he doesn't have any errors on the console, he just crashes!
I'm thinking of leaving the field in the bd as a date.
The input leave as text. Then in create it shows right 18/06/2020, but when I edit it it shows 2020-06-18
I don't use the moment and I can't use it because I use another library in the project and if I use the moment it conflicts.
If I do like this:
in create it correctly shows DD/MM/YYYY, however, in edit, it shows bd format YYYY-MM-DD
Well, let's go.
I have and should use it this way.
When I use create, it formats the perfect date 18/06/2020.
When I use the edit, it brings me a totally wrong date: 06/12/2025.
In my bd it's like 2020-06-18, in json it's like 2020-06-18.
How do I get the correct date in edit mode?
And, as in the time of recording, to correctly record the date in the bd in this case?
I can't find a solution for that. Honestly, the complicated business saw it!
Could you give me a link to the page that is crashing when the date picker for
datetime
is shown please? That shouldn't be happening, and I'm not aware of any other reports matching that, so I'd like to debug it.Allan
If you have to use jQuery UI date picker, you'll need to change the date format in the JSON. It expects only a single format - I don't think it will translate between a wire format and what is displayed (although you could ask their support channels).
Normally a get formatter would be used on the server-side for it. However, as I say, the
datetime
input should work and if it isn't it needs to be resolved.Allan
Hi Allan.
So you say that I better convert the date to php and take it to json in DD / MM / YYYY format. It is !?
If so, when editing / creating to save to bd, how do I really do it?
Good Morning. Could someone help me or go through a path that really resolves this issue?
I'll explain again in detail.
My bd date is by default mysql YYYY-MM-DD
I need to show it on the editor's screen in DD / MM / YYYY format. This I am already managing using:
However, I need that, when editing, it shows the date of the bd, converted to this format and, when I click save in the edit, it will save in the YYYY-MM-DD format.
Can someone for God's sake help me?
Yes - that's how I would do it. Here is an example.
Allan
OK.
My json is already returning DD / MM / YYYY.
In the editor I use:
But it does not write correctly in mysql nor in the edit does it show the correct date that is already recorded in mysql.
See what happens.
The instant I edit, I record a DD / MM / YYY date (12/12/2020)
and I open the edit again, it shows me a totally wrong date. I need to refresh the page to open the editor and it will show the correct date.
If you could give me a link to the page so I can debug it, that would be useful please.
Thanks,
Allan
I don't have Alan, I'm testing everything locally.
Look, I'm going to detail it entirely.
First:
In the editor I use:
My json is already returning DD / MM / YYYY.
Second:
I'm using in the editor:
In my comic, I have a date (YYYY-MM-DD = 2020-06-19)
When I open the editor, it shows the right date 19/06/2020.
I change the date to 20/06/2020 and record.
I open the editor again and a date appears nothing to do. I need to refresh the screen, open the editor again to show the right date.
Can you show me the JSON response to the create / edit action you are performing please?
Your "comic"?
Thanks,
Allan
hehe .... sorry, it was the translator here, I don't know what happened.
I meant "in my bd"
response create:
{"data":[{"DT_RowId":"row_36","id":"36","clipaccod":"14","clipacnom":"TESTE","clipacenddsc":"XXX","clipacendnum":"13","clipaccompl":"XXX","clipacbairro":"XXX","clipaccidade":"XXX","clipacuf":"XX","clipaccep":"xxx","clipacrg":"XXX","clipaccpf":"XXX","clipacdatnas":"2020-06-19","clipacnac":"XXX","clipactelfixo":"xxx","clipactelcel":"xxx","clipacemail":"xxx","clipacstatus":"A"}]}
response edit:
{"data":[{"DT_RowId":"row_1","id":"1","clipaccod":"1","clipacnom":"JESUS CRISTO","clipacenddsc":"XXX","clipacendnum":"1","clipaccompl":"XXX","clipacbairro":"XXX","clipaccidade":"XXX","clipacuf":"XX","clipaccep":"xxx","clipacrg":"XXX","clipaccpf":"XXX","clipacdatnas":"2020-06-19","clipacnac":"XXX","clipactelfixo":"xxx","clipactelcel":"xxx","clipacemail":"xxx","clipacstatus":"A"}]}
But Alan, the recording is working. I don't think you understand what I tried to explain.
When I edit the date, and open the editor again afterwards, the date shows a totally wrong date. I need to refresh the page and open the editor again for the date to show correctly.
It is a lot of back, a lot for a simple date formatting in this system.
There would be no need for so much work, so much code for a simple input date !!!!!
Sir, I am leaving this .... more than 3 days in it and no effective solution !!!!
Can you help me with this, please ????
That way it is not worth purchasing this tool .... It is soooo much work for a single little thing !!!!!
Every hour is a problem!
Blank date that looks like 1969-12-31, date that doesn't work when editing, display, anyway .... Sir !!!!!
Look at the thing ...
For me to be able to sort a date column, I have to keep using separate JS, the datatable just doesn't do it!
How many seams do we have to make to run a little business that should be simple!
Unless someone shows me and convinces me that I don't need it all.
Look, hard to see .... Now I understand you don't answer me anymore!