PluginProbe
Gravity Forms Eway / 2.2.4
Gravity Forms Eway v2.2.4
2.7.0 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.7.0 1.8.0 2.0.0 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 All 56 releases
gravityforms-eway / js / recurring.js

recurring.js in Gravity Forms Eway 2.2.4, at js/recurring.js

78 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /*!
2 gravityforms-eway
3 copyright (c) 2012-2016 WebAware Pty Ltd
4 Recurring Payments field
5 */
6
7 // initialise form on page load
8 (function($) {
9
10 var thisYear = (new Date()).getFullYear(),
11 yearRange = thisYear + ":2099", // year range for max date settings, mumble mumble jquery-ui mumble
12 reDatePattern = /^[0-9]{4}-[0-9]{2}-[0-9]{2}$/, // regex test for ISO date string
13 setPickerOptions = false;
14
15 // set datepicker minimum date if given
16 $("input[data-gfeway-minDate]").each(function() {
17 var input = $(this),
18 minDate = this.getAttribute("data-gfeway-minDate");
19
20 // if minDate is an ISO date string, convert to a Date object as a reliable way to set minDate
21 if (reDatePattern.test(minDate)) {
22 minDate = new Date(minDate);
23 }
24
25 input.datepicker("option", "minDate", minDate);
26 setPickerOptions = true;
27 });
28
29 // set datepicker maximum date if given
30 $("input[data-gfeway-maxDate]").each(function() {
31 var input = $(this),
32 maxDate = this.getAttribute("data-gfeway-maxDate");
33
34 // if maxDate is an ISO date string, convert to a Date object as a reliable way to set maxDate
35 if (reDatePattern.test(maxDate)) {
36 maxDate = new Date(maxDate);
37 }
38
39 input.datepicker("option", "yearRange", yearRange); // need to reset year range so can extend max date!
40 input.datepicker("option", "maxDate", maxDate);
41 setPickerOptions = true;
42 });
43
44 // hack: setting options on datepicker fields after initialisation makes the datepicker div show at the bottom of the page
45 if (setPickerOptions) {
46 $("#ui-datepicker-div").hide();
47 }
48
49 /**
50 * set recurring field to active, until otherwise advised by conditional logic triggers
51 * @param {jQuery.Event} event
52 * @param {Number} form_id int ID of Gravity Forms form
53 */
54 $(document).on("gform_post_render", function(event, form_id) {
55 $("#gform_" + form_id + " .gfeway-contains-recurring").addClass("gfeway-recurring-active");
56 });
57
58 // watch for conditional logic changes
59 gform.addAction("gform_post_conditional_logic_field_action", function(formId, action, targetId, defaultValues, isInit) {
60 var target = $(targetId);
61
62 if (target.hasClass("gfeway-contains-recurring")) {
63 if (action === "show") {
64 target.addClass("gfeway-recurring-active").removeClass("gfeway-recurring-inactive");
65
66 // reset fields to initial values
67 target.find("input.datepicker").each(function() {
68 this.value = this.getAttribute("value");
69 });
70 }
71 else {
72 target.addClass("gfeway-recurring-inactive").removeClass("gfeway-recurring-active");
73 }
74 }
75 });
76
77 })(jQuery);
78