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

Silent value updates, no callbacks #279

Closed
alan-andrade opened this issue Nov 21, 2013 · 7 comments
Closed

Silent value updates, no callbacks #279

alan-andrade opened this issue Nov 21, 2013 · 7 comments

Comments

@alan-andrade
Copy link

I'm using pickadate and I need to update the value of the picker but I don't need the callback onSet to be triggered.

Is there a way of setting 'select' without calling callbacks ?

@amsul
Copy link
Owner

amsul commented Nov 25, 2013

There’s no way to do this at the moment.

Why do you feel the need for this? If you want to just update the value to be formatted differently, you should be setting the format option.

Cheers.

@salmankhann
Copy link

I need this too... the scenario is as follows:

I have a pickadate whose value I set programatically with an ajax call. After loading this value, the user can change the date to what he wishes, but upon doing so an auto ajax call is made to the server to update the date.

The problem is that when I set the date programatically, the onSet event is triggered which makes a pointless ajax call to the server. Isn't there a way for the onSet event to be triggered only when the user manually selects a date from the picker?

Thanks.

@alan-andrade
Copy link
Author

This is the workaround I had to create.

    function silent_set( picker, date ) {
      picker.component.item.select = {
        year: date.getFullYear()
        , month: date.getMonth()
        , date: date.getDate()
        , day: date.getDay()
        , obj: date
      };
      // Dat hack!!!
      var value =
        picker.
        component.
        formats.
        toString.
        apply(
          picker.component,
          [ picker.component.settings.format,
            picker.component.get('select')
          ]);

      picker.set( 'highlight', date );
      picker.$node.val( value ).trigger( 'change' );
      picker.render();
    }

@alan-andrade
Copy link
Author

It would be nice to update the picker value with no user interaction. For example:

picker.on({
   set: function () {
       alert('you selected:' + e.select);
   }
});

// Somewhere else

setTimeout(function(){
   picker.set( 'select', new Date());
},1000);

After 1 second, we don't want to alert the user of the selection, we would like to set it silently (skipping the onSet callback)

@salmankhann
Copy link

Did you place the slient_set function in the original source file or somewhere in your js file?

I agree that the ability of silent setting of dates is required specially if in the select event handler we make an ajax call to the server...

Thanks...

@amsul amsul closed this as completed in f4cbdad Dec 5, 2013
@amsul
Copy link
Owner

amsul commented Dec 5, 2013

Added with v3.3.1: http://amsul.ca/pickadate.js/api.htm#muted-callbacks

Cheers :)

@alan-andrade
Copy link
Author

We appreciate this! Thank you very much @amsul :D

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

No branches or pull requests

3 participants