BUG-7569 Date Fields are not applying the mask when displaying saved dates.

When applying the mask it was showing a rear message. I added some mask letters in 'masktophp' function, to give solution this issue, and I added some validations to apply the mask when displaying saved dates.
This commit is contained in:
jennylee
2012-12-03 18:47:53 -04:00
parent 6c76ef1076
commit 366b06acb5

View File

@@ -4057,10 +4057,12 @@ class XmlForm_Field_Date extends XmlForm_Field_SimpleText
//$this->defaultValue = G::replaceDataField( $this->defaultValue, $owner->values); //$this->defaultValue = G::replaceDataField( $this->defaultValue, $owner->values);
$id = "form[$this->name]"; $id = "form[$this->name]";
if ($this->renderMode != 'edit' && $value == 'today') { if ($this->renderMode == 'edit' && $this->renderMode == 'view') {
$mask = str_replace( "%", "", $this->mask ); if ($value == 'today') {
$value = date( masktophp($mask) ); $mask = str_replace( "%", "", $this->mask );
return $value; $value = date( masktophp($mask) );
return $value;
}
} }
return $this->__draw_widget( $id, $value, $owner ); return $this->__draw_widget( $id, $value, $owner );
} }
@@ -4169,8 +4171,8 @@ class XmlForm_Field_Date extends XmlForm_Field_SimpleText
$mask = '%Y-%m-%d'; //set default $mask = '%Y-%m-%d'; //set default
} }
if ($this->defaultValue == "today") { if ($this->defaultValue != "") {
$defaultValue = masktophp( $mask ); $defaultValue = masktophp( $mask );
} }
if (strpos( $mask, '%' ) === false) { if (strpos( $mask, '%' ) === false) {
@@ -4210,15 +4212,8 @@ class XmlForm_Field_Date extends XmlForm_Field_SimpleText
if (trim( $value ) == '' or $value == null) { if (trim( $value ) == '' or $value == null) {
$value = ''; //date ($tmp); $value = ''; //date ($tmp);
} else { } else {
switch (strtolower( $value )) { if ($value != "") {
case 'today': $value = masktophp( $mask );
$value = masktophp( $mask ); // $value = date($tmp);
break;
default:
if (! $this->verifyDateFormat( $value )) {
//$value='';
break;
}
} }
} }
@@ -5473,6 +5468,39 @@ function masktophp ($mask)
if (preg_match('/S/',$tmp)) { if (preg_match('/S/',$tmp)) {
$tmp = str_replace("S", "s", $tmp); $tmp = str_replace("S", "s", $tmp);
} }
if (preg_match('/o/',$tmp)) {
$tmp = str_replace("o", "n", $tmp);
}
if (preg_match('/a/',$tmp)) {
$tmp = str_replace("a", "D", $tmp);
}
if (preg_match('/l/',$tmp)) {
$tmp = str_replace("l", "g", $tmp);
}
if (preg_match('/A/',$tmp)) {
$tmp = str_replace("A", "l", $tmp);
}
if (preg_match('/I/',$tmp)) {
$tmp = str_replace("I", "h", $tmp);
}
if (preg_match('/j/',$tmp)) {
$tmp = str_replace("j", "z", $tmp);
}
if (preg_match('/k/',$tmp)) {
$tmp = str_replace("k", "G", $tmp);
}
if (preg_match('/e/',$tmp)) {
$tmp = str_replace("e", "j", $tmp);
}
if (preg_match('/u/',$tmp)) {
$tmp = str_replace("u", "N", $tmp);
}
if (preg_match('/p/',$tmp)) {
$tmp = str_replace("p", "A", $tmp);
}
if (preg_match('/P/',$tmp)) {
$tmp = str_replace("P", "a", $tmp);
}
$value = date($tmp); $value = date($tmp);
return $value; return $value;
} }