Editor field - type: 'datetime

Editor field - type: 'datetime

menashemenashe Posts: 196Questions: 43Answers: 2

I have two date fields--start and end--on my Editor form. As I often "back enter" data several months old, I would like the END date to default to the same month that I enter for the Start date.

How can I do this?

                {
                    label: "Start:",
                    name: 'prices.sale_start',
                    type: 'datetime',
                    // def: function() {
                    //     return new Date();
                    // },
                    displayFormat: 'MM/DD/YYYY',
                    wireFormat: 'YYYY-MM-DD',
                    keyInput: true,
                    opts: {
                        firstDay: 0
                    }
                },
                {
                    label: "End:",
                    name: 'prices.sale_end',
                    type: 'datetime',
                    // def: function() {
                    //     return new Date();
                    // },
                    displayFormat: 'MM/DD/YYYY',
                    wireFormat: 'YYYY-MM-DD',
                    keyInput: true,
                    opts: {
                        firstDay: 0
                    }
                },

Answers

  • allanallan Posts: 63,516Questions: 1Answers: 10,473 Site admin

    You could use the dependent() method. That will trigger a callback function when your sale_end field is set. You could add a check to see if there is a value in sale_start before setting the value.

    Allan

  • menashemenashe Posts: 196Questions: 43Answers: 2

    Thank you!

    Almost there, but I cannot figure out how to 'set' a date field??

            pricesEditor.dependent('prices.sale_start', function(val, data, callback, e) {
                if (val != null) {
                    pricesEditor.field('prices.sale_end').set(...);
                }
    
                callback(true);
            });
    
  • menashemenashe Posts: 196Questions: 43Answers: 2

    I wish I could withdraw the question! :)

        pricesEditor.field('prices.sale_end').set(val);
    
  • allanallan Posts: 63,516Questions: 1Answers: 10,473 Site admin

    :) No worries - good to hear you've got it working!

    Allan

Sign In or Register to comment.