freqdec / datePicker

An attempt at writing a flexible, framework free, feature-rich and accessible datepicker
http://freqdec.github.io/datePicker/
MIT License
171 stars 56 forks source link

Passing dynamic element ID's to datePicker #33

Closed SSTMettersWebDev closed 10 years ago

SSTMettersWebDev commented 10 years ago

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.?

freqdec commented 10 years ago

Try this:

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