Skip to content

Commit

Permalink
Dev: fix js date validation
Browse files Browse the repository at this point in the history
Dev: validateInput() function was not called
  • Loading branch information
mfaber committed Nov 10, 2013
1 parent 67f7d13 commit 8a76fad
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
3 changes: 2 additions & 1 deletion application/helpers/qanda_helper.php
Expand Up @@ -1286,7 +1286,8 @@ function do_date($ia)

$goodchars = str_replace( array("m","d","y"), "", $dateformatdetails['jsdate']);
$goodchars = "0123456789".substr($goodchars,0,1);
$iLength=strlen($dateformatdetails['dateformat']);
// "+1" makes room for a trailing space in date/time values
$iLength=strlen($dateformatdetails['dateformat'])+1;

// HTML for date question using datepicker
$answer="<p class='question answer-item text-item date-item'><label for='answer{$ia[1]}' class='hide label'>{$clang->gT('Date picker')}</label>
Expand Down
13 changes: 6 additions & 7 deletions scripts/date.js
Expand Up @@ -21,9 +21,7 @@ function doPopupDate(qId){
firstDay: "1",
duration: 'fast',
// set more options at "runtime"
beforeShow: setPickerOptions,
// Validate input. Necessary because datepicker also allows keyboard entry.
onClose: validateInput,
beforeShow: setPickerOptions
}, $.datepicker.regional[language]);
}
}
Expand Down Expand Up @@ -59,7 +57,8 @@ function setPickerOptions(input)
var bshowButtonPanel=true;
var bshowTimepicker=true;
var sonSelect = '';
var sonClose = '';
// Validate input. Necessary because datepicker also allows keyboard entry.
var sonClose = validateInput(basename);
var balwaysSetTime = true;

//Configure the layout of the picker according to the format of the field
Expand Down Expand Up @@ -125,14 +124,13 @@ function setPickerOptions(input)
onSelect: sonSelect,
dateFormat: sdateFormat,
timeFormat: stimeFormat,
onClose: sonClose,
onClose: sonClose
};
}

function validateInput(input)
function validateInput(basename)
{
if(typeof showpopup=="undefined"){showpopup=1;}
var basename = this.id.substr(6);
format=$('#dateformat'+basename).val();
answer=$('#answer'+basename).val();
//only validate if the format mask says it's a complete date and only a date
Expand All @@ -148,6 +146,7 @@ function validateInput(input)
{
if(showpopup)
{
$(".ui-datepicker-calendar").hide();
alert(translt.alertInvalidDate);
}
$('#answer'+basename).val("");
Expand Down

0 comments on commit 8a76fad

Please sign in to comment.