jQuery datepicker return on Ajax. Should I eval()?
I'm creating a form开发者_如何学编程 builder using Zend_Framework and jQuery. I've run into a hypothetical question, that I would like an answer to.
While building a form, the Ajax returns an element, that should be a datepicker. I know, that I can turn the input into a datepicker by using a default class, like .calendar
and to use livequery()
to re-bind the events to these inputs.
Now the problem arises when I need the datepickers to have different settings. For an example,
- A datepicker that allows all dates above 20/10/2010
- A datepicker that allows only sundays to be selected.
As far as I can tell, I have only 1 way to approach this problem:
Load the jQuery code it requires via Ajax, and then eval()
it.
Is this the right way to do this, and what could be the pitfalls of this, if I know that the code is properly sanitized?
If anyone can provide some better solution, please, do!
Once you have appended the datepicker element to the document, you should be able to create a new call on it. This would mean that every time you used the ajax it would create a new datepicker instance, but if you are changing the settings I'm pretty sure that's the only safe way to go about it. Add the new datepicker options to you success handler and go from there.
精彩评论