https://github.com/idearia/gf-time-conditional-field
Based on the selected date, you can output different times in the select
https://github.com/idearia/gf-time-conditional-field
gravityforms wordpress wordpress-plugin
Last synced: about 1 month ago
JSON representation
Based on the selected date, you can output different times in the select
- Host: GitHub
- URL: https://github.com/idearia/gf-time-conditional-field
- Owner: Idearia
- Created: 2018-02-14T17:20:46.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-08-31T11:01:58.000Z (over 7 years ago)
- Last Synced: 2025-03-02T16:18:22.047Z (about 1 year ago)
- Topics: gravityforms, wordpress, wordpress-plugin
- Language: JavaScript
- Size: 59.6 KB
- Stars: 2
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# HOW-TO
Add in function.php
```php
function form_time_conditions() {
ob_start();
?>
var timeFilters = [
function time_only_lunch(date, day) {
var regex = new RegExp(/^15[\/-]02[\/-]2018$/);
if( regex.test(date) )
return ['12:00', '12:30', '13:00', '13:30', '14:00'];
else
return false;
},
function time_only_dinner(date, day) {
var regex = new RegExp(/^14[\/-]02[\/-]2018$/);
if( regex.test(date) )
return ['19:00', '19:30', '20:00', '20:30', '21:00'];
else
return false;
},
function monday_only(date, day) {
if( day == 0 )
return ['17:00','18:00'];
else
return false;
},
function sunday_only(date,day) {
if( day == 6 )
return ['23:00', '23:30'];
else
return false;
}
];
'#input_1_5', 'timeselectId' => '#input_1_4'];
wp_localize_script( 'Idearia\Gf_Time_Conditional_Fieldcustom', 'config', $config );
}
add_action( 'wp_enqueue_scripts', 'form_time_conditions' );
```
In timeFilters you can add all the functions you want to be called on date update, but keep in mind:
1. every function have to return false or the list of times
2. every function must have 2 parameters `date`[dd/mm/yyy] and `day`[int from 0(monday) to 6(sunday)]
The handler for all the scripts is `Idearia\Gf_Time_Conditional_Fieldcustom`
Here is a clean Javascript example of timeFilters, you can use a js file to, and register it as a script.
```js
var timeFilters = [
function time_only_lunch(date, day) {
var regex = new RegExp(/^15[\/-]02[\/-]2018$/);
if( regex.test(date) )
return ['12:00', '12:30', '13:00', '13:30', '14:00'];
else
return false;
},
function time_only_dinner(date, day) {
var regex = new RegExp(/^14[\/-]02[\/-]2018$/);
if( regex.test(date) )
return ['19:00', '19:30', '20:00', '20:30', '21:00'];
else
return false;
},
function monday_only(date, day) {
if( day == 0 )
return ['17:00','18:00'];
else
return false;
}
];
```