Hi People,
All I want to do is set gravity forms so that YEARS in the past can NOT be selected OR shown when selecting a date for an event.
How can this be done?
Thanks
zebra webdesigns answers:
Hello Bms1979
its very simple
here is the jquery code
<script>
jQuery(document).ready(function($) {
if ( jQuery.isFunction(jQuery.fn.datepicker) ) {
$(".datepicker").datepicker({ minDate: 1 });
}});
</script>
add it to the footer script.
This is completely safe. only if datepicker jquery is loaded it will do the process and make sure it wont affect any other thing.
you can change the minDate I have set as 1 so that only from the next day they can select the date.
you can make it 0 if you want to select today.
one more thing the class I have used is generic. if you need you can supply the particular id of the input field.
like
$("#field-id").datepicker({ minDate: 1 });
This is already tested with gravity form and check the screenshot in below link
http://awesomescreenshot.com/0b62ogir6b
Carl Brook comments:
Hi Zebra,
OK This worked, however after testing I am getting the following error when trying to submit
<strong>Please enter a valid date in the format (dd/mm/yyyy)
</strong>
Thanks, any solution here
zebra webdesigns comments:
Hello Bms
can you PM the site URL
and add the following and see whether it helps
<script>
jQuery(document).ready(function($) {
if ( jQuery.isFunction(jQuery.fn.datepicker) ) {
$(".datepicker").datepicker({ minDate: 1 ,dateFormat: 'dd/mm/yyyy' });
}});
</script>
Carl Brook comments:
Hi Zebra,
I replaced the original with the one above and same error! PM'ing site.
Thanks
Arnav Joy answers:
you can place a check after form is submitted using following Hook of gravity form
http://www.gravityhelp.com/documentation/page/Gform_field_validation
Fahad Murtaza answers:
can you share the html generated by form, form id and fields id for the year fields. I think using a custom version of the following code is the solution.
add_filter('gform_field_content', 'modify_field', 10, 5);
function modify_field($modify_html, $field){
if($field['formId'] == 11){
if($field['id'] == 5){$modify_html = str_replace("something_here_to be_worked_with",$modify_html);}
}
return $modify_html;
}
There can also be a front end based solution if we have the html but I believe above is a better way to do it.
Fahad Murtaza comments:
or use the already available solution of field validation as Arnav suggests.
Fahad Murtaza comments:
or use the already available solution of field validation as Arnav suggests.