mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2026-01-03 07:32:32 +01:00
Fix parsing input date for eldy calendar when using short year
This commit is contained in:
@@ -7271,7 +7271,7 @@ class Form
|
|||||||
// Input area to enter date manually
|
// Input area to enter date manually
|
||||||
$retstring .= '<input id="' . $prefix . '" name="' . $prefix . '" type="text" class="maxwidthdate center" maxlength="11" value="' . $formated_date . '"';
|
$retstring .= '<input id="' . $prefix . '" name="' . $prefix . '" type="text" class="maxwidthdate center" maxlength="11" value="' . $formated_date . '"';
|
||||||
$retstring .= ($disabled ? ' disabled' : '');
|
$retstring .= ($disabled ? ' disabled' : '');
|
||||||
$retstring .= ' onChange="dpChangeDay(\'' . $prefix . '\',\'' . $langs->trans("FormatDateShortJavaInput") . '\'); "'; // FormatDateShortInput for dol_print_date / FormatDateShortJavaInput that is same for javascript
|
$retstring .= ' onChange="dpChangeDay(\'' . dol_escape_js($prefix) . '\',\'' . dol_escape_js($langs->trans("FormatDateShortJavaInput")) . '\'); "'; // FormatDateShortInput for dol_print_date / FormatDateShortJavaInput that is same for javascript
|
||||||
$retstring .= ' autocomplete="off">';
|
$retstring .= ' autocomplete="off">';
|
||||||
|
|
||||||
// Icon calendar
|
// Icon calendar
|
||||||
|
|||||||
@@ -222,37 +222,59 @@ function getObjectFromID(id){
|
|||||||
return theObject;
|
return theObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called after selection of a date to save details into detailed fields
|
// Called after the selection or typing of a date to save details into detailed fields
|
||||||
function dpChangeDay(dateFieldID, format)
|
function dpChangeDay(dateFieldID, format)
|
||||||
{
|
{
|
||||||
//showDP.datefieldID=dateFieldID;
|
//showDP.datefieldID=dateFieldID;
|
||||||
console.log("Call dpChangeDay, we save date into detailed fields from format = "+format);
|
console.log("Call dpChangeDay, we save date into detailed fields from format = "+format);
|
||||||
|
|
||||||
var thefield=getObjectFromID(dateFieldID);
|
var thefield = getObjectFromID(dateFieldID);
|
||||||
var thefieldday=getObjectFromID(dateFieldID+"day");
|
var thefieldday = getObjectFromID(dateFieldID+"day");
|
||||||
var thefieldmonth=getObjectFromID(dateFieldID+"month");
|
var thefieldmonth = getObjectFromID(dateFieldID+"month");
|
||||||
var thefieldyear=getObjectFromID(dateFieldID+"year");
|
var thefieldyear = getObjectFromID(dateFieldID+"year");
|
||||||
|
|
||||||
var date=getDateFromFormat(thefield.value, format);
|
var date = getDateFromFormat(thefield.value, format);
|
||||||
//console.log(date);
|
//console.log(date);
|
||||||
if (date)
|
if (date)
|
||||||
{
|
{
|
||||||
thefieldday.value=date.getDate();
|
thefieldday.value = date.getDate();
|
||||||
if(thefieldday.onchange) thefieldday.onchange.call(thefieldday);
|
if (thefieldday.onchange) thefieldday.onchange.call(thefieldday);
|
||||||
thefieldmonth.value=date.getMonth()+1;
|
thefieldmonth.value = date.getMonth()+1;
|
||||||
if(thefieldmonth.onchange) thefieldmonth.onchange.call(thefieldmonth);
|
if (thefieldmonth.onchange) thefieldmonth.onchange.call(thefieldmonth);
|
||||||
thefieldyear.value=date.getFullYear();
|
thefieldyear.value = date.getFullYear();
|
||||||
if(thefieldyear.onchange) thefieldyear.onchange.call(thefieldyear);
|
if (thefieldyear.onchange) thefieldyear.onchange.call(thefieldyear);
|
||||||
|
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
// Replace yyyy into yy
|
||||||
thefieldday.value='';
|
newformat = format.replace(/yyyy/g, 'yy');
|
||||||
if(thefieldday.onchange) thefieldday.onchange.call(thefieldday);
|
if (newformat != format) {
|
||||||
thefieldmonth.value='';
|
console.log("dpChangeDay, we try now from format = "+newformat);
|
||||||
if(thefieldmonth.onchange) thefieldmonth.onchange.call(thefieldmonth);
|
|
||||||
thefieldyear.value='';
|
var date = getDateFromFormat(thefield.value, newformat);
|
||||||
if(thefieldyear.onchange) thefieldyear.onchange.call(thefieldyear);
|
//console.log(date);
|
||||||
|
if (date)
|
||||||
|
{
|
||||||
|
thefieldday.value = date.getDate();
|
||||||
|
if (thefieldday.onchange) thefieldday.onchange.call(thefieldday);
|
||||||
|
thefieldmonth.value = date.getMonth()+1;
|
||||||
|
if (thefieldmonth.onchange) thefieldmonth.onchange.call(thefieldmonth);
|
||||||
|
thefieldyear.value = date.getFullYear();
|
||||||
|
if (thefieldyear.onchange) thefieldyear.onchange.call(thefieldyear);
|
||||||
|
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
thefieldday.value = '';
|
||||||
|
if (thefieldday.onchange) thefieldday.onchange.call(thefieldday);
|
||||||
|
thefieldmonth.value = '';
|
||||||
|
if (thefieldmonth.onchange) thefieldmonth.onchange.call(thefieldmonth);
|
||||||
|
thefieldyear.value = '';
|
||||||
|
if (thefieldyear.onchange) thefieldyear.onchange.call(thefieldyear);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -337,13 +359,13 @@ function formatDate(date,format)
|
|||||||
* Licence: GPL
|
* Licence: GPL
|
||||||
* ==================================================================
|
* ==================================================================
|
||||||
*/
|
*/
|
||||||
function getDateFromFormat(val,format)
|
function getDateFromFormat(val, format)
|
||||||
{
|
{
|
||||||
// alert('getDateFromFormat val='+val+' format='+format);
|
// alert('getDateFromFormat val='+val+' format='+format);
|
||||||
|
|
||||||
// Force parameters en chaine
|
// Force parameters en chaine
|
||||||
val=val+"";
|
val = val+"";
|
||||||
format=format+"";
|
format = format+"";
|
||||||
|
|
||||||
if (val == '') return 0;
|
if (val == '') return 0;
|
||||||
|
|
||||||
@@ -356,17 +378,14 @@ function getDateFromFormat(val,format)
|
|||||||
var seconde=now.getSeconds();
|
var seconde=now.getSeconds();
|
||||||
|
|
||||||
var i=0;
|
var i=0;
|
||||||
var d=0; // -d- follows the date string while -i- follows the format
|
var d=0; // -d- follows the date string while -i- follows the format string
|
||||||
// string
|
|
||||||
|
|
||||||
while (i < format.length)
|
while (i < format.length)
|
||||||
{
|
{
|
||||||
c=format.charAt(i); // Recupere char du format
|
c=format.charAt(i); // Recupere char du format
|
||||||
substr="";
|
substr="";
|
||||||
j=i;
|
j=i;
|
||||||
while ((format.charAt(j)==c) && (j < format.length)) // Recupere char
|
while ((format.charAt(j)==c) && (j < format.length)) // Get successive similar characters
|
||||||
// successif
|
|
||||||
// identiques
|
|
||||||
{
|
{
|
||||||
substr += format.charAt(j++);
|
substr += format.charAt(j++);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user