Skip to content

Commit

Permalink
Fixed issue #7976: Date question: keyboard entries not validated
Browse files Browse the repository at this point in the history
Dev: when using the keyboard on the datepicker,
Dev: in the date/time question, invalid dates could be entered
Dev: and submitted. Added validation for dates.
  • Loading branch information
mfaber committed Oct 3, 2013
1 parent 938366e commit 8ea6f1d
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions scripts/date.js
Expand Up @@ -8,15 +8,36 @@ $(document).ready(function(){
language=$('#datelanguage'+basename).val();
datemin=$('#datemin'+basename).val();
datemax=$('#datemax'+basename).val();

$(e).datepicker({ dateFormat: format,
showOn: 'both',
changeYear: true,
changeMonth: true,
defaultDate: +0,
beforeShow: customRange,
firstDay: "1",
duration: 'fast'
}, $.datepicker.regional[language]);
duration: 'fast',
// Validate input. Necessary because datepicker also allows keyboard entry.
onClose: function() {
format=$('#dateformat'+basename).val();
answer=$('#answer'+basename).val();
//only validate if the format mask says it's a complete date and only a date
var str_regexp = /^[mydMYD]{1,4}[-.\s\/][mydMYD]{1,4}[-.\/\s][mydMYD]{1,4}$/;
var pattern = new RegExp(str_regexp);
if (format.match(pattern)!=null)
{
try
{
newvalue=jQuery.datepicker.parseDate(format, answer);
}
catch(error)
{
alert('Date entered is invalid!');

This comment has been minimized.

Copy link
@Shnoulle

Shnoulle Oct 4, 2013

Collaborator

Need to test if $showpopup is true (mine is false ;) )

This comment has been minimized.

Copy link
@mfaber

mfaber Oct 4, 2013

Author Contributor

Thanks for pointing this out. Is there another method to alert the user?

This comment has been minimized.

Copy link
@Shnoulle

Shnoulle Oct 4, 2013

Collaborator

No, i don't think ... Not actually. ANd other method must replace default alert :)

If you look at "ranking.js" : no alert id show popup is set:
function sortableAlert (qID,showpopups)
{
if(showpopups){
txtAlert=$("#question"+qID+" .em_num_answers").text()
alert(txtAlert);
}
}

I really think 2.05 must have a lsalert system.
Default behaviour : alert(...) but can be easily updated ;)

Ps: maybe have a global bar showpup like lang and seperator is a good idea here.

$('#answer'+basename).val("");
}
}
},
}, $.datepicker.regional[language]);
});

// dropdown dates
Expand All @@ -41,7 +62,6 @@ function customRange(input)
};
}


function dateUpdater() {

if(this.id.substr(0,3)=='yea')
Expand Down

0 comments on commit 8ea6f1d

Please sign in to comment.