This question has been flagged
1 Reply
7332 Views

I am using odoo v11. I have tried the following code it will work but the issue is when e select some other date after that I want to set the current date, it is not selectable.for example: first I have select date 17/04/2019 after that I will change 17th to today, then today's date is not selectable.

var DateWidget = require('web.datepicker').DateWidget;

DateWidget.include({

  start: function(parent, options) {

          var self = this;

          if (this.__parentedParent.attrs.options.disable_past_date) {

          self.options['minDate'] = moment(new Date());

          }

          this._super.apply(this, arguments);

      }
});
Any help?

Avatar
Discard
Best Answer

Try this one,

var FieldDate = require('web.basic_fields').FieldDate;
FieldDate.include({
init: function () {
this._super.apply(this, arguments);
if (this.nodeOptions.disable_past_date) {     var d = new Date();                 d.setHours(0,0,0,0);
this.datepickerOptions['minDate'] = moment(d);
}
}
});


Repeat the code for the FieldDateTime for datetime fields


Avatar
Discard
Author

Thanks for the help.

Your code is also working, but the same issue(I have mentioned my issue) is reflected in your code too.

when you select other date value and after that, you want to reselect today's date it will not allow changing the date.

Author

var DateWidget = require('web.datepicker').DateWidget;

DateWidget.include({

start: function(parent, options) {

if (this.__parentedParent.attrs.options.disable_past_date) {

var min_date = new Date()

min_date.setHours(0)

min_date.setMinutes(0)

this.options['minDate'] = moment(min_date);

}

this._super.apply(this, arguments);

},

});

I have tried this code. It's works for me.

I have missed that part in your comment. I have updated the example 😅

BTW, You should never use this.__parentedParent directly some time it can break the things.

require('web.basic_fields').FieldDate is the last abstraction for the date picker for the form view so you should use it to avoid the side effects.

Author

ohk, Thank you for help