- Avoid incorrect validation after using datepicker

- Partly jQueryfy a function
- After fixing an incorrect value, the field remained red
This commit is contained in:
Marc Delisle
2011-01-14 09:20:09 -05:00
parent 867892816d
commit 2817ebe8e9
2 changed files with 36 additions and 37 deletions

View File

@@ -157,7 +157,6 @@ function isTime(val)
} }
function verificationsAfterFieldChange(urlField, multi_edit, theType){ function verificationsAfterFieldChange(urlField, multi_edit, theType){
var rowForm = document.forms['insertForm'];
var evt = window.event || arguments.callee.caller.arguments[0]; var evt = window.event || arguments.callee.caller.arguments[0];
var target = evt.target || evt.srcElement; var target = evt.target || evt.srcElement;
@@ -166,53 +165,49 @@ function verificationsAfterFieldChange(urlField, multi_edit,theType){
// Unchecks the Ignore checkbox for the current row // Unchecks the Ignore checkbox for the current row
$("input[name='insert_ignore_" + multi_edit + "']").attr({'checked': false}); $("input[name='insert_ignore_" + multi_edit + "']").attr({'checked': false});
$this_input = $("input[name='fields[multi_edit][" + multi_edit + "][" + urlField + "]']");
if(target.name.substring(0,6)=="fields") // Does this field come from datepicker?
{ if ($this_input.data('comes_from') == 'datepicker') {
var dt=rowForm.elements['fields[multi_edit][' + multi_edit + '][' + urlField + ']']; // Yes, so do not validate because the final value is not yet in
// validate for date time // the field and hopefully the datepicker returns a valid date+time
if(theType=="datetime"||theType=="time"||theType=="date"||theType=="timestamp") $this_input.data('comes_from', '');
{
if(theType=="date"){
if(!isDate(dt.value))
{
dt.className="invalid_value";
return false;
}
}
else if(theType=="time")
{
if(!isTime(dt.value))
{
dt.className="invalid_value";
return false;
}
}
else if(theType=="datetime"||theType=="timestamp")
{
tmstmp=false;
if(dt.value=="CURRENT_TIMESTAMP")
{
dt.className="";
return true; return true;
} }
if(theType=="timestamp")
{ if(target.name.substring(0,6)=="fields") {
// validate for date time
if(theType=="datetime"||theType=="time"||theType=="date"||theType=="timestamp") {
$this_input.removeClass("invalid_value");
var dt_value = $this_input.val();
if(theType=="date"){
if (! isDate(dt_value)) {
$this_input.addClass("invalid_value");
return false;
}
} else if(theType=="time") {
if (! isTime(dt_value)) {
$this_input.addClass("invalid_value");
return false;
}
} else if(theType=="datetime"||theType=="timestamp") {
tmstmp=false;
if(dt_value == "CURRENT_TIMESTAMP") {
return true;
}
if(theType=="timestamp") {
tmstmp=true; tmstmp=true;
} }
if(dt.value=="0000-00-00 00:00:00") if(dt_value=="0000-00-00 00:00:00") {
return true; return true;
var dv=dt.value.indexOf(" ");
if(dv==-1)
{
dt.className="invalid_value";
return false;
} }
else var dv=dt_value.indexOf(" ");
{ if(dv==-1) {
if(!(isDate(dt.value.substring(0,dv),tmstmp)&&isTime(dt.value.substring(dv+1)))) $this_input.addClass("invalid_value");
{ return false;
dt.className="invalid_value"; } else {
if (! (isDate(dt_value.substring(0,dv),tmstmp) && isTime(dt_value.substring(dv+1)))) {
$this_input.addClass("invalid_value");
return false; return false;
} }
} }

View File

@@ -988,6 +988,10 @@ $(function() {
<?php echo ($field['pma_type'] == 'date' ? "showTime: false,":"showTime: true,"); ?> <?php echo ($field['pma_type'] == 'date' ? "showTime: false,":"showTime: true,"); ?>
dateFormat: 'yy-mm-dd', // yy means year with four digits dateFormat: 'yy-mm-dd', // yy means year with four digits
altTimeField: '', altTimeField: '',
beforeShow: function(input, inst) {
// Remember that we came from the datepicker
$(input).data('comes_from', 'datepicker');
},
constrainInput: false constrainInput: false
}); });
}); });