Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery UI datepicker within jquery-confirm dialog

I'm using the jquery-confirm script from the link below. It has the capability to include a form field within a dialog box. You can see this by clicking on the "Act Like a Prompt" blue button at the link below.

I've got the form (a single field) set up, but I want this input to be a datepicker, and I don't know where I should put the javascript to make this happen since this form doesn't exist until the dialog is generated.

https://craftpip.github.io/jquery-confirm/

My dialog javascript:

            $('.deal_edit').on('click', function () {
            var id = $(this).attr('data-id');
            $.confirm({
                title: 'Change end Date',
                content: 'url:form.txt',
                confirm: function () {
                    var input = this.$b.find('input#new_end_date').val();
                    var errorText = this.$b.find('.text-danger');
                    if (input.val() == '') {
                        errorText.show();
                        return false;
                    } else {
                        var data = {action: 'edit_deal', id: id, new_date: new_date};
                        $.post('ajax.php', data, function(response) {

                            $.alert({
                                title: "Updated",
                                content: "Ok, record has been updated - this page will reload.",
                                confirm: function() {
                                    location.reload();
                                }   
                            });

                        });
                    }
                }
            });
            return false;
        });     

Contents of form.txt:

<p>The only editable field currently is 'deal end date'.  (This may change soon)</p>
<div class="form-group">
  <label>New End Date</label>
  <input autofocus type="text" id="new_end_date" name="new_end_date" class="form-control">
</div>
     <p class="text-danger" style="display:none">Please enter an end date, or click 'close'.</p>

Thank you!!!

like image 878
drumichael611 Avatar asked Jan 28 '26 15:01

drumichael611


2 Answers

I had the same issue, this is how I fix it.

You need to add events onOpen and onClose to the confirm dialog to add

        $.confirm({
            onOpen: function(){
                $( ".datepicker" ).datepicker();
            },
            onClose: function(){
                $(".datepicker").datepicker("destroy");
            },
            title: 'Change end Date',
            content: 'url:form.txt',
            confirm: function () {
                var input = this.$b.find('input#new_end_date').val();
                var errorText = this.$b.find('.text-danger');
                if (input.val() == '') {
                    errorText.show();
                    return false;
                } else {
                    var data = {action: 'edit_deal', id: id, new_date: new_date};
                    $.post('ajax.php', data, function(response) {

                        $.alert({
                            title: "Updated",
                            content: "Ok, record has been updated - this page will reload.",
                            confirm: function() {
                                location.reload();
                            }   
                        });

                    });
                }
            }
        });
like image 127
Jose Lopez Avatar answered Jan 31 '26 04:01

Jose Lopez


You can add code in the onContentReady event, like a function that is called after the plug-in create the dialog window. you can add this code to your example

 onContentReady: function () {
    $("#new_end_date").datetimepicker();
 }
like image 24
Steven R. Lizano Avatar answered Jan 31 '26 03:01

Steven R. Lizano



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!