Call jquery datepicker viewhelper from custom viewhelper

277 views Asked by At

I have a custom view helper in app/view/helper folder. The code for add text field is - in my code: $this->view->formText('date'); But instead of text field i want to add jquery datepicker like this: $this->view->datePicker('date');

But this does not work. Please help. Regards

1

There are 1 answers

0
David Weinraub On BEST ANSWER

In principle, you do not need a view helper for this.

On the client side, just attach the jQuery datapicker to your element. How you target that element with a client-side selector is dependent upon the DOM hooks you have available in your page/form, but as an example, assuming a form with id myForm and an input field with name myDate that you would like to function as a datepicker, you could simply use:

function($){
    $(document).ready(function(){
        $('#myForm input[name="myDate"]').datePicker({
            // datepicker options here
        });
    });
}(jQuery);

Of course, this presumes that jQuery is loaded when this runs and that the datepicker plugin is loaded by the time the ready event fires on the document object.