Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide and Show hijriDatePicker() and show text based on condition #10

Open
prakashjain opened this issue Dec 2, 2019 · 5 comments
Open

Comments

@prakashjain
Copy link

prakashjain commented Dec 2, 2019

Hello,

Normal datepicker support below code to hide datepicker.
$('#datepicker').datepicker("disable")

bootstrap-hijri-datetimepicker.js" lib picker.destroy function available:
picker.destroy = function () {
///
Destroys the widget and removes all attached event listeners
hide();
detachDatePickerElementEvents();
element.removeData('DateTimePicker');
element.removeData('date');
};

$('#datepicker').datepicker("disable") o hide how to implement in hijriDatePicker() in custom js ?
$(function () {
$("#hijri-date-input").hijriDatePicker();
});

$("#hijri-date-input").on('dp.hide', function (event) {
  // would like to hide hijriDatePicker()
 // if  locale: "ar-sa" (selection other than ar-sa) only show text field try many methods but //working
      });
    });
@balbarak
Copy link
Owner

balbarak commented Dec 3, 2019

Hello,

can you clearfiy what you are going to achieve ?

the picker data name is HijriDatePicker and you could use

$(element).removeData('HijriDatePicker');

if you want to destroy the datetime picker use the following

$("#hijri-date-input").data('HijriDatePicker').destroy();

Hope I get what you want to achieve

Thanks

@prakashjain
Copy link
Author

Yes, same thing want to achieve. but the above code not working.
Please see the below sample code.

<title> Bootstrap Hijri Date Picker </title>
<link href="css/bootstrap.css" rel="stylesheet" />
<link href="css/bootstrap-datetimepicker.css" rel="stylesheet" />
<div class="container">
    <div class="py-5 text-center">
        <h2>Checkout form</h2>
        <p class="lead">Below is an example form built entirely with Bootstrap’s form controls. Each required form group has a validation state that can be triggered by attempting to submit the form without completing it.</p>
    </div>

    <div class="row">
        <div class="col-md-6">

            <div class="form-group">
                <div class="input-group date">
                    <input type='text' class="form-control" id="hijri-date-input" />
                         <select id="locale" name="lang">
                                      <option value="show" selected="selected">Show</option>
                                      <option value="hide">Hide</option>
                                </select>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="js/jquery-3.3.1.js"></script>
<script src="js/bootstrap.js"></script>
<script src="js/momentjs.js"></script>
<script src="js/moment-with-locales.js"></script>
<script src="js/moment-hijri.js"></script>
<script src="js/bootstrap-hijri-datetimepicker.js"></script>

<script type="text/javascript">


    $(function () {
        initHijrDatePicker();
    });

  $("#locale").on("change", function() {
  if($(this).val()=='hide') {
    $("#hijri-date-input").data('HijriDatePicker').destroy();
    //$(#hijri-date-input).removeData('HijriDatePicker');
  }
  if($(this).val()=='show') {
  alert("Showing");
    initHijrDatePicker();
    //$(#hijri-date-input).removeData('HijriDatePicker');
  }
});

    function initHijrDatePicker() {
        $("#hijri-date-input").hijriDatePicker({
            locale: "en",
            format: "DD-MM-YYYY",
            //hijriFormat:"iYYYY-iMM-iDD",
            //dayViewHeaderFormat: "MMMM YYYY",
            //hijriDayViewHeaderFormat: "iMMMM iYYYY",
            showSwitcher: true,
            allowInputToggle: true,
            showTodayButton: false,
            useCurrent: true,
            isRTL: false,
            keepOpen: false,
            hijri: true,
            debug: true,
            showClear: true,
            showTodayButton: true,
            showClose: true
        });
    }


    function initHijrDatePickerDefault() {
        $("#hijri-date-input").hijriDatePicker();
    }


</script>

@balbarak
Copy link
Owner

balbarak commented Dec 6, 2019

try to call this code alone and see if the datepicker get destoyed or not

$("#hijri-date-input").data('HijriDatePicker').destroy()

Thanks

@prakashjain
Copy link
Author

prakashjain commented Jan 10, 2020

Sorry for the late reply.
$("#hijri-date-input").data('HijriDatePicker').destroy()
Yes the above code working to destroy, but after destroy using below code to display Hijr Date picker
initHijrDatePicker();
But now showing. I would like to show/hide Hijr date picker based on selection on change called
initHijrDatePicker(); method but not showing calendar view.

@balbarak
Copy link
Owner

Soon, we will improve the docs and list all features.

Hope you will find what are you looking for

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants