javascript - Angular uib-datepicker-popup default date displayed -


sometimes very, simple thing gets way over-complicated. have datepicker popup set , want default today's date if no model value available. used "initdate" config option, , set default date in popup, not in textbox date displayed. textbox of datepicker have date, seems 1 of 2 conditions must met: 1. model has date value assigned. 2. user selects date datepicker. unacceptable me. why include option set default date, if highlight default date's button, , doesn't display in textbox?

the existence of date in model triggers logic in presentation , saving of model, it's not acceptable set model date. need supply default date, , have reflected in widget, in same manner had model date's value been set. can this? it's extremely aggravating. widget useful, has loads of excellent options , behaviors, , i've written controller handles using widget in date range. end of range want default applied. not assigned value model, default. suggestions?

per request, code...

// class uib-datepicker config options. export class datepickerconfig {     public formatyear: string;     public formatmonth: string;     public formatday: string;     public mindate: date;     public maxdate: date;     public initdate: date; }  // controller handles setting config options , disabling restricted dates.  export class datepickerrangecontroller {      // you'd think config objects set format popup, ain't case.     public dppopupdateformat: string;      // start/end date config objects.     public startdpoptions: datepickerconfig;     public enddpoptions: datepickerconfig;      // boolean values indicate whether or not datepicker popup open. setting 'true' causes popup open.     public startdpopened: boolean;     public enddpopened: boolean;      // allow end of date range future date.      public allowfutureenddate: boolean;      static $inject = [     ];      constructor() {         super();         this.initialize();     }      private initialize() {         // have used config options build this, that's pain. worthwhile if format          // being built dynamically, in supporting multiple formats. 1 format supported @ present.         this.dppopupdateformat = 'mm/dd/yyyy';          // basic config options.          this.startdpoptions = new datepickerconfig();         this.startdpoptions.initdate = new date();         this.startdpoptions.formatyear = 'yyyy';         this.startdpoptions.formatmonth = 'mm';         this.startdpoptions.formatday = 'dd';                      // copy values other config object.         this.enddpoptions = angular.copy(this.startdpoptions);                      // set initial value of these variables 'false'. popups won't open otherwise.         this.startdpopened = false;         this.enddpopened = false;     }      // code truncated brevity. } 

this in typescript, by. anyway, thought setting 'initdate' config option current day trick, , in sense does, because date highlighted on actual calendar (the button) date specified 'initdate'. it's far different when model set value, or user selects date. here's layout - have form date range, created controller takes in birth/death dates, , uses them set initial date selection restrictions (mindate, maxdate) start , end dates. due problem getting access object on page load, pass in model when either datepicker opened. same function runs every time 1 of datepickers opened, can update restricted start/end dates when values change. let's me ensure no 1 sets start date after end date, instance. handle default date problem (badly) setting end date in model, have requested behavior, pain. i'd need jump through number of hoops. can't modify model itself, date visible elsewhere on screen (in list view), , setting end date of model today make though end date set, when hasn't been. swap out cloned object, when saving i'd have check property of object , manually take out end date based on that. seems ridiculous set default date in popup.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -