Multiple editor names using one field

Multiple editor names using one field

mRendermRender Posts: 151Questions: 26Answers: 13

I'm looking for a way to do something like...

,{
                label: "Date:",
                name: "time.recorddate, time.startdate",
                type: "date",
                def: function () {return new Date(); },
                dateFormat: 'mm/dd/yy'
            },

Having to select multiple dates is a pain. Yes, they will always be the same. No, I didn't design this database.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,044Questions: 1Answers: 9,955 Site admin

    Sorry - there is no way for a single field to contain multiple fields. You would probably need a formatter on the server-side that would do the split for you, taking the time part and the date part from the submitted value.

    Allan

  • mRendermRender Posts: 151Questions: 26Answers: 13

    Just to clarify, I don't want to split the data in half. I want to insert the same value into 2 different columns in the database.

    I want a single datepicker field to return 11/18/2014 and insert it into both time.recorddate and time.startdate in the database.

    Still impossible, right?

  • allanallan Posts: 61,044Questions: 1Answers: 9,955 Site admin
    Answer ✓

    Oh I see. Not impossible - little is (in the programming world anyway!) - just needs a little "manipulation".

    One option would be to define a second field which is hidden and then in preSubmit set the value of the hidden field to match the visible one.

    The other option would be to have a trigger on your database table to take the value from one column and write it into the other on insert and update.

    Allan

  • mRendermRender Posts: 151Questions: 26Answers: 13

    For anyone who is looking for some help with this, here's what I did.

    Why? Good question. I don't want my user to select a starttime and endtime and recorddate. I want them to select a date ONCE, and use that value for all 3 fields. Now you can just hide the starttime and endtime in your editor and use this to make the values the same as recorddate :)

    editor.on( 'preSubmit', function ( e, d, type ) {
      if ( type === 'create' || type === 'edit' ) {
        var time = editor.field( 'time.recorddate' ).val();
        d.data.time.starttime = time;
        d.data.time.endtime = time;
      }
    } );
    
This discussion has been closed.