Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
8716 Widoki

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?

Awatar
Odrzuć
Najlepsza odpowiedź

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


Awatar
Odrzuć
Autor

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.

Autor

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.

Autor

ohk, Thank you for help

Powiązane posty Odpowiedzi Widoki Czynność
5
lip 23
18070
1
kwi 23
4108
2
lip 22
8926
1
cze 21
2218
2
lut 21
299