Created
January 6, 2021 18:06
-
-
Save danielcharrua/72fe5a36fde3d6f5a97545616e4c5c05 to your computer and use it in GitHub Desktop.
Add conditional fields depending on a date field
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
gform.addAction( 'gform_input_change', function( elem, formId, fieldId ) { | |
if ( fieldId == 13 ) { | |
valorCampoDate = elem.value; | |
var parts = valorCampoDate.split( '/' ); | |
// Presta atención al mes ( parts[1] ); JavaScript cuenta los meses desde 0: | |
// Enero - 0, Febrero - 1, etc. | |
var myDate = new Date( parts[2], parts[1] - 1, parts[0] ); | |
// Cambiar el valor del campo oculto. | |
var campoOculto = document.getElementById( 'input_1_27' ); | |
campoOculto.value = myDate.getDay(); | |
// Envía el evento change (es importante si no, no funcionará) | |
campoOculto.dispatchEvent( new Event( 'change', { bubbles: true } ) ); | |
} | |
}, 10, 3 ); | |
gform.addFilter( 'gform_datepicker_options_pre_init', function( optionsObj, formId, fieldId ) { | |
if ( fieldId == 13 ) { | |
// Deshabilitar domingos (día 0) | |
optionsObj.firstDay = 1; | |
optionsObj.beforeShowDay = function(date) { | |
var day = date.getDay(); | |
return [(day != 0)]; | |
}; | |
// Deshabilitar fechas menores a la actual | |
optionsObj.minDate = 0; | |
} | |
return optionsObj; | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment