Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onChange fires before setting the date #124

Open
na7r1x opened this issue Mar 22, 2018 · 4 comments
Open

onChange fires before setting the date #124

na7r1x opened this issue Mar 22, 2018 · 4 comments

Comments

@na7r1x
Copy link

na7r1x commented Mar 22, 2018

Title pretty much sums it up. The onChange function is called before the changes are applied.
Example: whenever the date is changed I'd like to do stuff with the value of that date. So, naturally, I'd do this in the onChange function, retrieving the date with $('#mycalendar').calendar('get date'). However, when I do this, I get null initially and the previous value on consecutive changes.

  • first change
    image

onChange: function() {
console.log('change triggered');
console.log('current value ' + $('#endDate').val());
}

-result:

image

  • second change
    image

  • result:

image

  • however, in reality:

image

Is this behaviour intentional and if it is, why?! Why would I want to trigger an onChange function before I've done the changes? Or am I missing something obvious?

@onlyargon
Copy link

Can you provide a sample code?

@lubber-de
Copy link

lubber-de commented Jan 22, 2019

As the calendar has been merged into Fomantic-UI, this issue is further discussed in fomantic/Fomantic-UI#417

@lubber-de
Copy link

lubber-de commented Sep 3, 2019

Fixed and prepared for Fomantic-UI 2.8.0 by fomantic/Fomantic-UI#982

@jafidiesel
Copy link

jafidiesel commented Nov 26, 2019

A workaround for those who still use semantic could be this:

onChange: function(date, text, mode)
where date it's the datetime selected. I know it's not the actual value from the input but it's the one that will be set there.

$("#rangestart_machinery").calendar({
    ampm: false,
    type: "date",
    maxDate: new Date(),
    formatter: {
      date: function(date, settings) {
        if (!date) return "";
          var momentDate = moment(date).format("YYYY/MM/DD").split("/");
          return momentDate[0] + "/" + momentDate[1] + "/" + momentDate[2];
        },
      cell: function(cell, date, cellOptions) {
        var dateCurrent = moment(date).format("YYYY-MM-DD");
        for (var i = datesCellsEnd.length - 1; i >= 0; i--) {
          if (datesCellsEnd[i] == dateCurrent) {
            $(cell).css("background-color","#f93b69");
            $(cell).css("color","white");
          }
        }  
      }
    },
    today: true,
    onChange: function(date, text, mode) {
      const dateFrom = moment(date).format('YYYY-MM-DD')
      const dateTo = moment($('#rangeend_machinery').calendar('get date')).format('YYYY-MM-DD')
      renderChartsPromMachinery(machine_id, dateFrom, dateTo);
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants