Dynamically change highlighted dates in Jquery Datepicker - javascript

hi
I have a Jquery Datepicker object that is created fine with no highlighted dates and a particular minDate.
I want to add a highlights to this datepicker based on an AJAX call made by the user, but the only way I can see to change the highlights is adding a function to the beforeShowDay event, which is set on setup.
How can I change this function on an existing datepicker and force it to redraw so that I get my new date(s) to be highlighted.
Many thanks everyone.
Dave

Right the only way I could find to do this is to use the destroy method then redraw the picker with the new method attached to it. If anyone knows a better way of doing this please add it and I'll give you the answer.
Thanks
EDIT: Code...
Setup the picker...
var datePickerSettings = {
beforeShowDate: beforeShowDateMethod
};
var alternateDatePickerSettings = {
beforeShowDate: beforeShowDateMethodAlternate
};
$('#mydiv').datepicker(datePickerSettings);
Then once callback is complete
$('#mydiv').datepicker('destroy')
$('#mydiv').datepicker(alternateDatePickerSettings);
In the end I didn't use the date picker as the requirements changed, but this should solve the problem
Dave

There is the setDate method of the datepicker. I cannot link directly but it is here http://jqueryui.com/demos/datepicker/ under methods

Related

How to perform click on DateRangePicker using Chrome Selenium C#

I am looking for a way to perform mouse click on DateRangePicker element.
I tried to write a tool for automation on https://rvshare.com/.
I need to click on DateRangePicker. I tried all the ways that are available on the internet but no luck.
Here are 3 ways I tried.
// 1.
Driver.FindElement(by).Click();
// 2.
Driver.ExecuteScript("arguments[0].click('');", ((RemoteWebDriver)Driver).FindElement(by));
// 3.
Actions action = new Actions(Driver);
action.MoveToElement(Driver.FindElement(by)).Perform();
action.Click(Driver.FindElement(by)).Perform();
The calendar controls are supposed to be shown but any of the above does not work.
Is there anybody who encountered similar issues?
I'm not sure what was your problem, but I was able to click on Datepicker(Pickup or Dropoff) using 1st method you mentioned, so I suggest that issue is not with methods u r using, but with your locator.
Your code is gonna be:
Driver.FindElement(By.XPath("//div[#class='DateRangePickerInput_arrow DateRangePickerInput_arrow_1']/following::div[#class='DateInput DateInput_1']")).Click();
If you are trying to select the data from the calendar then use the below script once you click on the either Pickup or Dropoff. The xpath works for both of them. Make sure to enter the date in the right format and you month you want to select is there in the calendar. You have to click on move to next month button until you reach the required month.
driver.FindElement(By.Xpath("//td[contains(#aria-label,'May 14, 2019')]")).click();

Disable click on other date (Datepicker without Jquery UI)

Based on here I need to disable date change in condition.
example:
var count = 0 ;
if (count = 0){cannot click on other date}
Please guide me on this, ive read other posts and i cannot use same approach.
I need to disable clicking on other date, when i was working on process related on one particular date. As an example, i was working on a form that use the current week, then suddenly i clicked on other date on mistakes, and the date will change to new date. i want to avoid thi
Thanks.
Try this line inside your if condition
var dat=document.getElementById('#idDate');
dat.setAttribute('readonly',true);

update label with selected date when selecting date in asp calendar

I have a asp calendar (i want to continue to use that calendar. NOT the jquery one)
When a date is selected in the calendar, i want to put that date in a label. I tried to write a piece of javascript, but it doesn't work. Can anyone help me point out what i am doing wrong?
Thanks!
<script type="text/javascript">
$('#Calendar1').change(function() {
var t1 = $('#Calendar1').val();
var result = t1;
$('#lbldate').html(result);
});
</script>
All the calendar is is a table with links. The best way to do this would be attach to a link click by capturing all of the link clicks using JQuery, or in the DayRender event, write out some javascript to call your own function with the current date. Not 100% sure how to do that, but DayRender lets you have access to a lot, so it should be possible.
The calendar control was really never meant to work client-side in this fashion, so you may run into quirks to work around because of that.

jQuery UI datetimepicker bound to wrong input after DOM element removed

Here's something to bake everyone's noodle. I have a form on a website. You can look at it: My Website. Click book me and select a certain number of days at the top right. Manually remove a few of the form lines from the form using the '-' button. Then try to use the first input on the first line. It's linked to the wrong input. All the inputs have unique ID attributes, and I rebind datetimepicker class after a line is removed. Anyone have the foggiest idea why the datetimepicker pointing the the wrong object? Ironically enough, the timepicker portion, which is not from jQuery UI proper, still points to the correct input, it would seem. It seems that when you delete lines of a lower number, the lines of a higher number are moved and renamed, but the date portion f the datetime picker is still pointing the the line number that it was originally bound to, if that makes any sense.
Help is appreciated because this one has me stumped. I've tried manually releasing the datepicker objects before I remove the form lines, but nothing seems to help.
Thanks
Edit: Is there a way to completely destroy the instances of the datepicker that are bound to the input elements before I remove them?
Edit: Alright, I just had a realization. I am destroying the datepickers on the lines I'm removing, but not the lines that remain, so I'm going to work on this for a minute and see if destroying the datepickers completely when i rebuild the form helps.
No time to analyse all that code but could possible help to call $(elem).datetimepicker('destroy') when you remove a control before any rebinding.
In setAlts()
try removing var fields = $('.date').get();
and just doing:
$('.date').each(function() {
$(this).datetimepicker('destroy'); // From Marcell
$(this).datetimepicker({
minDate: now,
timeFormat: "h:mm tt",
stepMinute: 15,
});
});
If you remove dateCheck() all should be fine.
I assume below is what you are intending with dateCheck() though.
Ok in dateCheck()
change:
target.siblings('.date').datetimepicker('setDate', dateMin);
to:
target.next('.date').datetimepicker('minDate', dateMin);
Alright, so to answer the question: It seems obvious in retrospect, but the datetimepicker addon which is coded in a slightly different, and probably less efficient, manner was throwing me off the trail. At any rate, I'll try to explain what was happening in a clear fashion.
The datepicker object binds to the id of the element when it is created, and it keeps that id until it is destroyed. And apparently, attempting to bind a new datepicker object does nothing if there is already a datepicker object present.
To rememdy the problem, in the setAlts() method, I simply destroyed every single datepicker object, and recreated it. Pretty simple, but it was confusing the hell out of me.
And thanks for setting me on the right path. Otherwise I'd have probably had a chimpout and started smearing my poo on the walls.

Knockout with Jquery UI datepicker date display

Please see this link for details http://jsfiddle.net/pakpatel/5p6Uz/4/
Can we do the range in Datepicker, If first date choose [ 10/12/2012 ] then second date shouldn't be before 10/12/2012, Customer can select date after ex.[10/13/2012] in datepicker.
Could anyone explain me how to implement. Thanks in advance.
By using the previous row's data as the new min, it makes it challenging.
Working demo is at http://jsfiddle.net/photo_tom/5p6Uz/24/
There were two things that were required.
Added a computed observable to pass the previous row's choosedate value to the current row.
Added a new minDate binding to set the mindate option on the date picker.
This is not a completed fiddle. It doesn't properly handle adds or deletes. This is because the ko.computables need to be rebuilt.
EDIT:
Updated to handle add / delete methods. Interesting problem, trying to transfer information between two different rows in the table. Good challenge.
Soution at http://jsfiddle.net/5p6Uz/34/.

Categories