RETURN DEF - Page 2

RETURN DEF

2

Replies

  • lauromnetolauromneto Posts: 129Questions: 0Answers: 0

    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);
    }
    });
    });

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    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) {
    

    Colin

  • lauromnetolauromneto Posts: 129Questions: 0Answers: 0

    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.

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    The best way is to set displayFormat for datetime, as that allows you to display it differently to how it is sent to the server,

    Colin

  • lauromnetolauromneto Posts: 129Questions: 0Answers: 0

    Thank you very much Colin and sorry for the delay.
    God bless everything there!

  • lauromnetolauromneto Posts: 129Questions: 0Answers: 0

    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.

  • colincolin Posts: 15,142Questions: 1Answers: 2,586
    edited June 2020

    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`.

    Hopefully that will do the trick,

    Colin

  • lauromnetolauromneto Posts: 129Questions: 0Answers: 0
    edited June 2020

    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:

    {
    label: "DATE ​​OF BIRTH:",
    name: "clipacdatnas",
    type: "date",
    },
    

    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.

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    As I said, use datetime, with the options I suggested - see example here.

    Colin

  • lauromnetolauromneto Posts: 129Questions: 0Answers: 0

    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 !

  • kthorngrenkthorngren Posts: 20,269Questions: 26Answers: 4,765

    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

    Do you get errors in your browser's console?

    Kevin

  • lauromnetolauromneto Posts: 129Questions: 0Answers: 0

    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

  • lauromnetolauromneto Posts: 129Questions: 0Answers: 0

    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:

    {
        label: "DATE ​​OF BIRTH:",
        name: "clipacdatnas",
        // type: 'date',   ////////// delete
        def: function () {
        return $ .datepicker.formatDate ('dd / mm / yy', new Date ());
        },
    }
    

    in create it correctly shows DD/MM/YYYY, however, in edit, it shows bd format YYYY-MM-DD

  • lauromnetolauromneto Posts: 129Questions: 0Answers: 0

    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!

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin

    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

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin

    How do I get the correct date in edit mode?

    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

  • lauromnetolauromneto Posts: 129Questions: 0Answers: 0

    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?

  • lauromnetolauromneto Posts: 129Questions: 0Answers: 0

    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?

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin

    So you say that I better convert the date to php and take it to json in DD / MM / YYYY format. It is !?

    Yes - that's how I would do it. Here is an example.

    Allan

  • lauromnetolauromneto Posts: 129Questions: 0Answers: 0

    OK.
    My json is already returning DD / MM / YYYY.

    In the editor I use:

    {
    label: "DATE ​​OF BIRTH:",
    name: "clipacdatnas",
                    type: 'date',
                    def: function () {return new Date (); },
                    dateFormat: 'dd / mm / yy',
    },
    

    But it does not write correctly in mysql nor in the edit does it show the correct date that is already recorded in mysql.

  • lauromnetolauromneto Posts: 129Questions: 0Answers: 0

    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.

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin

    If you could give me a link to the page so I can debug it, that would be useful please.

    Thanks,
    Allan

  • lauromnetolauromneto Posts: 129Questions: 0Answers: 0

    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.

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin

    Can you show me the JSON response to the create / edit action you are performing please?

    In my comic, I have a date (YYYY-MM-DD = 2020-06-19)

    Your "comic"?

    Thanks,
    Allan

  • lauromnetolauromneto Posts: 129Questions: 0Answers: 0

    hehe .... sorry, it was the translator here, I don't know what happened.
    I meant "in my bd"

  • lauromnetolauromneto Posts: 129Questions: 0Answers: 0

    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"}]}

  • lauromnetolauromneto Posts: 129Questions: 0Answers: 0

    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.

  • lauromnetolauromneto Posts: 129Questions: 0Answers: 0

    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 !!!!

  • lauromnetolauromneto Posts: 129Questions: 0Answers: 0

    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 !!!!!

  • lauromnetolauromneto Posts: 129Questions: 0Answers: 0

    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!

This discussion has been closed.