Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
1 Vastaa
8793 Näkymät

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
Hylkää
Paras vastaus

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
Hylkää
Tekijä

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.

Tekijä

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.

Tekijä

ohk, Thank you for help

Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
5
heinäk. 23
18222
1
huhtik. 23
4286
2
heinäk. 22
9037
1
kesäk. 21
2311
2
helmik. 21
299