Need help to figure out why my endDateCtrl is not updating.
I have the following JavaScript/JQuery code... I have been asked to pick this up from a developer who left. I am stumped as there are two DatePicker controls and one of the controls is set while the other one is not set.
The results display in a grid and then show in a panel with the datepicker controls. The event, clicking on the 'Edit' link in the grid populates two fields:
Here is the code:
return { init: function (ctrl_IDs) { _benefitPlans.pop(); _categories.pop(); _definitions.pop(); _diagGroups.pop(); _ageGroups.pop(); _placeOfServices.pop(); _serviceID = getServiceID(); if (ctrl_IDs) { _ids = ctrl_IDs; } initialHideEditPanels(); initialButtonDisable(); bindDatePickerEvents(); bindButtonEvents(); bindInputBlurEvents(); bindCheckboxEvents(); bindRadGridEvents(); initialDataBind(); toggleServiceCodeInputEnabled(false); toggleBenefitPlanInputEnabled(false); } }
function bindDatePickerEvents() { bindDates($find(_ids.txtServiceCodeEffectiveDate), $find(_ids.txtServiceCodeEndDate)); bindDates($find(_ids.txtBenefitPlanEffectiveDate), $find(_ids.txtBenefitPlanEndDate), _attrTypes.benefitPlan);//TODO RBD SW#6848 bindDates($find(_ids.txtServiceCategoryEffectiveDate), $find(_ids.txtServiceCategoryEndDate), _attrTypes.serviceCategory); bindDates($find(_ids.txtServiceDefinitionEffectiveDate), $find(_ids.txtServiceDefinitionEndDate), _attrTypes.serviceDefinition); bindDates($find(_ids.txtDiagnosisGroupEffectiveDate), $find(_ids.txtDiagnosisGroupEndDate), _attrTypes.diagnosisGroup); bindDates($find(_ids.txtAgeGroupEffectiveDate), $find(_ids.txtAgeGroupEndDate), _attrTypes.ageGroup); bindDates($find(_ids.txtPlacesOfServiceEffectiveDate), $find(_ids.txtPlacesOfServiceEndDate), _attrTypes.placeOfService); }
function bindDates(effDate, endDate, attrType) { //Declare variables to be used in the JavaScript Function var effDateID = effDate.get_id(); var endDateID = endDate.get_id(); var tmp = attrType; $(effDate.get_element()).on('validDateEntered', { effID: effDateID, endID: endDateID, type: tmp }, function (evt) { setEffectiveDates($find(evt.data.effID), $find(evt.data.endID), evt.data.type); }); effDate.add_dateSelected(function (sender, args) { validateDatesRange(effDate, endDate); }); effDate.get_dateInput().add_blur(function (sender, args) { validateDatesRange(effDate, endDate); }); endDate.add_dateSelected(function (sender, args) { validateDatesRange(effDate, endDate); }); endDate.get_dateInput().add_blur(function (sender, args) { validateDatesRange(effDate, endDate); }); }
//TODO RBD ----- FIND THE MISSING END_DATE ISSUE function setEffectiveDates(effDateCtrl, endDateCtrl, attrType) { var type = attrType !== undefined ? attrType : -1, effDate = effDateCtrl.get_selectedDate(), endDate = endDateCtrl.get_selectedDate(), effDateString = effDate == undefined ? '' : dateToString(effDate), endDateString = endDate == undefined ? '' : dateToString(endDate); switch (type) { //RBD CODING ON SATURDAY MORNING CARTOONS case _attrTypes.benefitPlan: _selected.benefitPlan.eff_date = effDateString; _selected.benefitPlan.end_date = endDateString; break; case _attrTypes.serviceCategory: _selected.serviceCategory.eff_date = effDateString; _selected.serviceCategory.end_date = endDateString; break; case _attrTypes.serviceDefinition: _selected.serviceDefinition.eff_date = effDateString; _selected.serviceDefinition.end_date = endDateString; break; case _attrTypes.diagnosisGroup: _selected.diagnosisGroup.eff_date = effDateString; _selected.diagnosisGroup.end_date = endDateString; break; case _attrTypes.ageGroup: _selected.ageGroup.eff_date = effDateString; _selected.ageGroup.end_date = endDateString; break; case _attrTypes.placeOfService: _selected.placeOfService.eff_date = effDateString; _selected.placeOfService.end_date = endDateString; break; default: _details.eff_date = effDateString; _details.end_date = endDateString; break; } }
function validateDatesRange(effDateCtrl, endDateCtrl) { var result = true, effDate = effDateCtrl.get_selectedDate(), endDate = endDateCtrl.get_selectedDate(), cell = $(effDateCtrl.get_element()).parents('td').first(); if (effDate && endDate) { if (effDate > endDate) { var div = "<div class='errorMessage' style='display:none;'>Effective date must be less than end date.</div>"; $(div).prependTo(cell).fadeIn(); result = false; } } if (result) { cell.find('div.errorMessage').fadeOut(200, null, function () { $(this).remove(); }); $(effDateCtrl.get_element()).trigger('validDateEntered'); } return result; }
Now the ultimate problem is the effDateCtrl is updating as it should, but the endDateCtrl is not.
I am really stumped and wondering if anybody can help me out.