Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
1 Ответить
8794 Представления

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

Related Posts Ответы Просмотры Активность
5
июл. 23
18222
1
апр. 23
4286
2
июл. 22
9037
1
июн. 21
2311
2
февр. 21
299