pheromix
pheromix

Reputation: 19307

Cannot prevent the datepicker from showing after making a field readonly

There is a field attached to datepicker :

...
<input type="text" class="datepicker chp_" name="dateDebut" />
...

<?php $this->load->view("footer"); ?>

<script type="text/javascript">
$(document).ready(function() {

    var idSpecialite = "<?php echo $this->session->userdata('idSpecialite'); ?>";

    if (idSpecialite != 4) {

        $("#tab1").find(".chp_").each(function(){
            $(this).attr("readonly","");
            if ($(this).hasClass("datepicker")) {
                $(this).removeClass("datepicker");
            }
        });

    }

});

In the footer there is this :

<script type="text/javascript">
     ...
    $(function() {

        $(".datepicker").datepicker({
            language: 'fr',
            autoclose: true
        });

    });
</script>

As you can see I want the field to be non-editable in a particular condition. But at runtime when I click the field then the picker still shows and the field's value can be changed when selecting a date ! So how to not show the picker in this case ?

Upvotes: 0

Views: 55

Answers (2)

pheromix
pheromix

Reputation: 19307

ok , I used the disabled attribute then the picker did not show :

if (idSpecialite != 4) {

    $("#tab1").find(".chp_").each(function(){
        $(this).attr("disabled",true);
    });

}

Upvotes: 1

Ray A
Ray A

Reputation: 1341

try to use this code to make it read-only

$this.attr('readonly','readonly');

also make sure that the value of idSpecialite is not 4, you can convert the result to integer to see it, like this:

var idSpecialite = parseInt("<?php echo $this->session->userdata('idSpecialite'); ?>");

Upvotes: 1

Related Questions