vitalets / combodate

Dropdown date and time picker
http://vitalets.github.com/combodate
207 stars 82 forks source link

Clear Combodate Value #37

Open mangeshskulkarni opened 9 years ago

mangeshskulkarni commented 9 years ago

Hi,

Can you please guide me how I can clear the value of a Combodate whose value is already set. I tried using $('#date').combodate('setValue',''); but this did not do the trick.

Thanks

mbreuer23 commented 8 years ago

+1

mbreuer23 commented 8 years ago

I just added my own clearValue method, which you can call via $(el).combodate('clearValue') Seems to do the trick.

    clearValue: function() {
      var that = this;

      $.each(this.map, function(k, v) {
        if(that['$'+k]) {
            that['$'+k].val("");
        }
      });

      this.datetime = null;

    },
Simon-Wilson commented 8 years ago

+1

Simon-Wilson commented 8 years ago

@mbreuer23. Would you mind at all elaborating on your fix for a js noob? Where would you place that snippet of code you provided?

mbreuer23 commented 8 years ago

I put it in comdodate.js, inside the definition for Combodate.prototype. So for example, you could put it immediately before the getValue function

        //.....
         /*
        fill ampm
        */
        fillAmpm: function() {
            // ...
        },
        clearValue: function() {
            // paste code here
        },

        /*
         Returns current date value from combos.
         If format not specified - `options.format` used.
         If format = `null` - Moment object returned.
        */
        getValue: function(format) {
        // .....
        } ,
      //  ......
Simon-Wilson commented 8 years ago

Thank you sir, @mbreuer23, works like a charm. Really appreciate your help.

lilybluecat commented 8 years ago

nice work! thanks a lot.

ddanurwenda commented 7 years ago

Excellent works! I do recommend you to use this value in the setValue function as well, so that setValue(null) will trigger the clearValue

jo-soft commented 7 years ago

i also added this to my fork https://github.com/jo-soft/combodate