I have a form where a user can request a date to discontinue services. I would like to disable the ability to select weekends if possible since we are not open on weekends. Any information will be appreciated. Thank you for your time.
Question
Question
How to disable weekends on date time field
Answer
This will do it.
Add the class "myDate" to your date field and copy in this JavaScript.
I want to note that this is not my original code. A couple years ago, someone here helped me with code that would limit my datepicker to only Sunday, and all I've done here is tweak that a bit for you.
I hope this helps!
/*Limits date selection exclude weekends*/ $(document).ready(function(){ function isCorrectDate(n) { var t = n.getDay(); var d = n.getDate(); return (t!=0 && t!=6); } function checkDate(n) { return[isCorrectDate(n),""]; } function checkField(input, inst) { if ($(input).closest('li').hasClass('myDate')) { $(input).datepicker("option", {beforeShowDay: checkDate}); } } $.datepicker.setDefaults( {beforeShow: checkField} ); window.Parsley.addValidator('secondsat', { validateString: function(value) { return isCorrectDate(new Date(value)); }, messages: { en: 'Not valid date.' } }); $('.myDate input').attr('data-parsley-secondsat',''); });
Thank you. It works amazingly in Classic Designer, but can't seem to get it working in Layout Designer (the current form I have).
Given Matthew's response below, I think you'll have to stick with Classic Designer to make this work (unless more JS functionality is added to the new designer in the future).
That's correct. This is not going to be possible in the Layout Designer.
Javascript written for the Classic Designer cannot usually be copied directly to the Layout Designer as the structure of the form is completely differently.
Additionally, the Layout Designer runs the Javascript within a sandboxed iFrame, so it cannot directly modify components of the form. It can only make changes that have been made available via the LFForm interface.
So this is not going to be possible on the Layout Designer unless a future release includes the ability to do this via the LFForm interface.
Replies
Which designer are you using? The Forms Layout Designer (New Designer) or the Classic Forms Designer?
You're probably not going to be able to achieve this on the Forms Layout Designer with the current functionality available. The Javascript runs within a sandboxed iFrame and cannot directly modify fields, and the default structure of the field doesn't have the ability to be configured in the way you would need.
But there are several examples here on LFAnswers with the Classic Forms Designer to achieve this kind of functionality using Javascript/JQuery. Such as this one, this one, this one, this one, and this one.