freqdec / datePicker

An attempt at writing a flexible, framework free, feature-rich and accessible datepicker

Home Page:http://freqdec.github.io/datePicker/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Passing dynamic element ID's to datePicker

SSTMettersWebDev opened this issue · comments

I'm trying to create a datePicker calendar instance based on a dynamic element ID from a jQuery cloned table row. $clTRow is the cloned row:
$clTRow.find("a").each(function(){
var orig = (this.id.match(/\d+$/) || [0])[0];
var num = +(this.id.match(/\d+$/) || [0])[0] + 1;
var inputName = "sf215Date_" + orig + "" + num;
var inputTitle = "SF215 Date " + orig + "
" + num;

                this.id = this.id.replace(/\d+$/, "") + orig + "_" +num ;
                this.href = this.href.replace(this.href, "") +  "#" + $clTRow.find('input[id^="sf215Date_"]').attr('id');
                this.title = this.title.replace(this.title, "") + inputTitle;

/*when I try to create the option string dynamicly it places quotes around the string which I believe invaidates it. */
var opts = '{formElements:{'+ inputName + ': "m-sl-d-sl-Y"},calendarIconTitle :' + inputTitle + '};';

/* if I put the variable name in it takes it as a string literal */
var opts = {formElements:{inputName : "m-sl-d-sl-Y"},calendarIconTitle :inputTitle };

/* if I use eval() around the var name, it tells me that I'm missing a semi colon*/
var opts = {formElements:{eval("inputName") : "m-sl-d-sl-Y"},calendarIconTitle :eval ("inputTitle")};

datePickerController.createDatePicker(opts);

            });

Is there any way to pass in a dynamicly generated ID and Title.?

Try this:

var opts = {'formElements':{}};
opts.formElements[inputName] = 'm-sl-d-sl-Y';