Last active
April 2, 2020 20:03
-
-
Save raulingg/d9968406e0bd461459fd591cbf43ea32 to your computer and use it in GitHub Desktop.
Script to validate the application form of the Laboratoria's admission process in Instapage
This file contains 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> | |
ijQuery(document).ready(function() { | |
$('.page-block') | |
.first() | |
.addClass('stickyheader') | |
var firstSection = $('.stickyheader').height() | |
$('body').css('margin-top', firstSection) | |
}) | |
</script> | |
<script type="text/javascript"> | |
ijQuery(document).ready(function() { | |
// _Translate.set( original in English, translated ); | |
_Translate.set('Processing...', 'Procesando...') | |
_Translate.set( | |
'Please Fix These Errors', | |
'Por favor, corrige los siguientes errores:' | |
) | |
_Translate.set('is required', 'es obligatorio.') | |
}) | |
</script> | |
<script> | |
$(document).ready(function() { | |
$('h4').click(function() { | |
$(this) | |
.nextUntil('h4') | |
.slideToggle() | |
$(this).toggleClass('ui-closed ui-open') | |
}) | |
}) | |
</script> | |
<script> | |
var cohortIds = { | |
'Ciudad de México': 'cdmx-2019-06-pre-core-admission', | |
Guadalajara: 'gdl-2019-06-pre-core-admission', | |
Lima: 'lim-2020-03-pre-core-admssion', | |
'Santiago de Chile': 'scl-2019-06-pre-core-admission', | |
'Sao Paolo': 'spl-2019-06-pre-core-admission' | |
} | |
ijQuery(document).ready(function() { | |
setTimeout(function() { | |
ijQuery('form').each(function() { | |
this.reset() | |
var selectElements = document.querySelectorAll('form select') | |
selectElements.forEach(function(element) { | |
element.value = '' | |
}) | |
}) | |
}, 4000) | |
var variation = window.__variant | |
ijQuery('input[name="TGFuZGluZyBWZXJzaW9u"]').val(variation) | |
var preguntas = [ | |
'¿Cuáles son las etapas que debes completar para postular a Laboratoria?', | |
'¿Cuál es el lenguaje que aprenderás durante el bootcamp?' | |
] | |
var respuestas = [ | |
'Aplicación en línea - Entrevista - Pre-admisión', | |
'JavaScript' | |
] | |
var pregunta_0 = false | |
var pregunta_1 = false | |
function check_true() { | |
if (pregunta_0 == true && pregunta_1 == true) { | |
ijQuery('input[name="QXByb2JhZGE="]').val('true') | |
} else { | |
ijQuery('input[name="QXByb2JhZGE="]').val('false') | |
} | |
} | |
ijQuery('select[name="wr9BIHF1w6kgc2VkZSBkZXNlYXMgcG9zdHVsYXI/"]').change( | |
function() { | |
var city = this.value | |
var cohortId = cohortIds[city] || cohortIds['Lima'] | |
// Update cohortId hidden field | |
ijQuery('input[name="Y29ob3J0SWQ="]')[0].value = cohortId | |
} | |
) | |
ijQuery('.field-element').change(function() { | |
//chequear si la pregunta está en lista de preguntas que reviso - chequear si respuesta está siendo observada | |
if ( | |
preguntas.indexOf(base64_decode(this.childNodes[1].name)) > -1 && | |
respuestas.indexOf(this.childNodes[1].value) > -1 | |
) { | |
if (respuestas.indexOf(this.childNodes[1].value) == 0) { | |
pregunta_0 = true | |
} else if (respuestas.indexOf(this.childNodes[1].value) == 1) { | |
pregunta_1 = true | |
} | |
check_true() | |
} else if ( | |
preguntas.indexOf(base64_decode(this.childNodes[1].name)) > -1 && | |
respuestas.indexOf(this.childNodes[1].value) < 0 | |
) { | |
if (preguntas.indexOf(base64_decode(this.childNodes[1].name)) == 0) { | |
pregunta_0 = false | |
} else if ( | |
preguntas.indexOf(base64_decode(this.childNodes[1].name)) == 1 | |
) { | |
pregunta_1 = false | |
} | |
check_true() | |
} | |
}) | |
}) | |
window.instapageFormSubmitSuccess = function(form) { | |
var fname = ijQuery(form) | |
.find('input[name="' + base64_encode('Nombre') + '"]') | |
.val() | |
var email = ijQuery(form) | |
.find('input[name="' + base64_encode('Correo Electrónico') + '"]') | |
.val() | |
var city = ijQuery(form) | |
.find( | |
'select[name="' + base64_encode('¿A qué sede deseas postular?') + '"]' | |
) | |
.val() | |
var aprobada = ijQuery(form) | |
.find('input[name="' + base64_encode('Aprobada') + '"]') | |
.val() | |
if (aprobada === 'true' && cohortIds.hasOwnProperty(city)) { | |
ijQuery(form) | |
.find('input[name="redirect"]') | |
.val('http://admissionsuccess.pagedemo.co/') | |
} else { | |
ijQuery(form) | |
.find('input[name="redirect"]') | |
.val('http://convocatoria.laboratoria.la/mas-informacion') | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment