跳至内容
菜单
此问题已终结
1 回复
8788 查看

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?

形象
丢弃
最佳答案

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


形象
丢弃
编写者

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.

编写者

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.

编写者

ohk, Thank you for help

相关帖文 回复 查看 活动
5
7月 23
18221
1
4月 23
4282
2
7月 22
9032
1
6月 21
2301
2
2月 21
299