Skip Navigation

[Resolved] Populate minDate value of a datepicker with a post type value

This support ticket is created 6 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 10 replies, has 2 voices.

Last updated by nabils 6 years, 3 months ago.

Assisted by: Shane.

Author
Posts
#1077336

Dear,
I have a form with a datePicker.
Here my JS:
$( "#"+from ).datepicker({
changeMonth: true,
changeYear: true,
minDate: new Date(2018, 09 - 1, 15),...
This works and my datepicker minimum date is set to the desired date. However, This date can be variable so I saved it in [types field='first-day-of-semester' style='text' format='F j, Y' id="643"][/types] (as global variable), but could not set mindate to this value of type field.

I tried with a generic field in my form:
first day:[cred_generic_field field='firstday' type='textfield' class='' urlparam='']
{
"required":0,
"validate_format":0,
"default":"1537128000000"
}
[/cred_generic_field]
My idea was to put [types field='first-day-of-semester' style='text' format='F j, Y' id="643"][/types] as default value of the generic field and then use this generic field default value in my JS to set minDate, but could not. Any clue please?

Regards
Nabil

#1077496

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Nabils,

Thank you for contacting our support forum.

I'm a bit lost here. Lets try taking it a step at a time.

So the first issue is that you want the generic CRED field's default value to be set by another post's custom field value correct?

If so then you can do it like this.

[cred_generic_field field='firstday' type='textfield' class='' urlparam='']
{
"required":0,
"validate_format":0,
"default":"[types field='first-day-of-semester' style='text' format='F j, Y' id='643'][/types]"
}
[/cred_generic_field]

Please try this and let me know.

Thanks,
Shane

#1077505

Thank you Shane,
Actually my final aim is to set minDate of datepicker to
[types field='first-day-of-semester' style='text' format='F j, Y' id='643'][/types]
The generic field was a turnaround.

#1077579

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Nabils,

So essentially this field is what determines the semester start?

This is on a post in the backend and you want this to update automatically using your code ?

I'm still not 100% clear , however I know you want to use your code to set a default date but i'm not sure where you want to use the code.

Thanks,
Shane

#1077597

Dear Shane
Yes the field is to determine the semester start. Instead of using a direct value in datepicker such us:
Mindate: new Date (2018, 9 -1, 1),
I need to get the date from the user (using another form) and then populate the mindate of datepicker.
So it sould be something like:
Mindate: new Date (x)
Where x is the value of [types field='first-day-of-semester' style='text' format='F j, Y' id='643'][/types]
Thank you for your help

#1078506

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Nabils,

I must apologize for still not 100%.

So here is what I understood from your previous message.

"I need to get the date from the user (using another form) and then populate the mindate of datepicker."

I'm unclear here but i'm assuming that there is a fixed date somewhere and you don't want the user to select a date below that minimum date that is set somewhere else.

Please let me know .

Thanks,
Shane

#1078521

Hi
Yes, the admin will select the min date n another form. This date is stored in [types field='first-day-of-semester' style='text' format='F j, Y' id='643'][/types]. Now when the customer wants to select a date, the min date should be the one stored by the admin.

Thanks

#1078568

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Nabils,

What you can do as I just thought of this is to print the field value [types field='first-day-of-semester' style='text' format='F j, Y' id='643'][/types] in a tag somewhere on the page.

Then using jquery, get this value then you should be able to convert this date to an actual date in jquery using your code and set the min value to that date.

Please let me know if this is clear.

Thanks,
Shane

#1078713

Hi Shane
I didn't really understand what you mean by print the value in a tag.

#1078747

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

For e.g you can do this.

<p id='semester-start-date'>[types field='first-day-of-semester' style='text' format='F j, Y' id='643'][/types] </p>

Then you can use some css to hide this tag, while you use it for the jquery code.

Hopefully this makes it a little clearer.

Thanks,
Shane

#1080301

Thank you. It works