concrete5/concrete5 — pull request #557 by lehik (2012-06-22 08:26:46+00:00)
Title: Unique id's to date picker fields

Changes:
Added fourth parameter "$uniqueID" to FormDateTimeHelper date() -function. It defaults to an empty string to retain backward compatibility. The parameter is parsed exactly like the $id variable to strip out any special characters. An underscore is added to the front of the string, making it like "_myID". The parameter is then added to the date picker fields own id field.

Why?
Consider that you want to create multiple instances of Date Pickers on a page AND you want to submit the form results as an array, as following:

for($i=0;$i<10;$i++) {
$dt->date('myArr[]', $value, true);
}

It will create multiple date picker elements with identical ID's, which is bad markup and will break some javascripts. With the modified version, you can create multiple date pickers and each of them will get unique ID's, if desired. Example here:

for($i=0;$i<10;$i++) {
$dt->date('myArr[]', $value, true, $i);
}

The id's will be like myArr___0, myArr___1. The underscores are result of special characters [] being changed to underscores. Should that be changed to something more elegant?

NOTE: datetime() function is not modified at all. I or someone else can do it later if necessary.