Pareces nuevo por aquí. Si quieres participar, ¡pulsa uno de estos botones!
public/javascript/kumbia/fechas.jspaso 2
function esDigito(sChr){ var sCod = sChr.charCodeAt(0); return ((sCod > 47) && (sCod < 58)); } function valSep(oTxt){ var bOk = false; bOk = bOk || ((oTxt.value.charAt(2) == "-") && (oTxt.value.charAt(5) == "-")); bOk = bOk || ((oTxt.value.charAt(2) == "/") && (oTxt.value.charAt(5) == "/")); return bOk; } function finMes(oTxt){ var nMes = parseInt(oTxt.value.substr(3, 2), 10); var nRes = 0; switch (nMes){ case 1: nRes = 31; break; case 2: nRes = 29; break; case 3: nRes = 31; break; case 4: nRes = 30; break; case 5: nRes = 31; break; case 6: nRes = 30; break; case 7: nRes = 31; break; case 8: nRes = 31; break; case 9: nRes = 30; break; case 10: nRes = 31; break; case 11: nRes = 30; break; case 12: nRes = 31; break; } return nRes; } function valDia(oTxt){ var bOk = false; var nDia = parseInt(oTxt.value.substr(0, 2), 10); bOk = bOk || ((nDia >= 1) && (nDia <= finMes(oTxt))); return bOk; } function valMes(oTxt){ var bOk = false; var nMes = parseInt(oTxt.value.substr(3, 2), 10); bOk = bOk || ((nMes >= 1) && (nMes <= 12)); return bOk; } function valAno(oTxt){ var bOk = true; var nAno = oTxt.value.substr(6); bOk = bOk && ((nAno.length == 2) || (nAno.length == 4)); if (bOk){ for (var i = 0; i < nAno.length; i++){ bOk = bOk && esDigito(nAno.charAt(i)); } } return bOk; } function valFecha(oTxt){ var bOk = true; if (oTxt.value != ""){ bOk = bOk && (valAno(oTxt)); bOk = bOk && (valMes(oTxt)); bOk = bOk && (valDia(oTxt)); bOk = bOk && (valSep(oTxt)); if (!bOk){ alert("Fecha inválida"); oTxt.value = ""; oTxt.focus(); } } }paso 3:
library/kumbia/helpers/tags.php
function date_field_tag($name){ $params = is_array($name) ? $name : get_params(func_get_args()); if(!isset($params['onblur'])) { $params['onblur'] = "valFecha(this)"; } else { $params['onblur'].=";valFecha(this)"; } if(isset($params['format'])){ $format = $params['format']; unset($params['format']); } else { $format = "%d-%m-%Y"; } if(isset($params['theme'])){ $theme = $params['theme']; unset($params['theme']); } else { $theme = "theme-1"; } if(isset($params['language'])){ $language = $params['language']; unset($params['language']); } else { $language = "calendar-es"; } if(isset($params[0])) { $params = array_merge(get_id_and_name($params[0]), $params); } $code = ''; $code .= javascript_library_tag('jscalendar/calendar'); $code .= javascript_library_tag('jscalendar/calendar-setup'); $code .= javascript_library_tag('fechas'); // página javacript q valida gecha $code .= text_field_tag($params); $code .= img_tag("calendar.gif","id: ".$params['id']."tigger","style: cursor: pointer;")."\n"; $code .= javascript_library_tag("jscalendar/$language"); $code .= stylesheet_link_tag("style-calendar/$theme", "true"); $script= " Calendar.setup({ \n". " inputField : '".$params['id']."', // ID of the input field \n". " ifFormat : '".$format."', // the date format \n". " daFormat : '".$format."', \n". " button : '".$params['id']."tigger"."' // ID of the button \n". " } \n". " ); \n"; $code .= xhtml_tag('script', 'type: text/javascript', "content: $script"); return $code; }