1

I'm working on this input right now using bootstrap 3.0 and bootstrap-datepicker from eternicode.

The problem is that I'm having by default the input to be disabled, because I do not want the user to be modifying the date by his hand.

I'm assigning an input addon with a glyphicon of a calendar to show the datepicker. The problem though is that whenever I select a date, the input doesn't receive the date. I've been going through the docs and there's a way to do it, but it is with Bootstrap 2.3.2 only.

Here is my code, does anybody know how can I transfer the selected date from the datepicker into my disabled input?

Help will be much appreciated!

html

<div class="form-group">
     <label class="control-label" for="fechaTandas">Fecha</label>
      <div class="input-group">
     <span class="input-group-addon date" id="trigger-datepicker"><span class="glyphicon glyphicon-calendar"></span></span>
   <input type="text" class="form-control" name="fechaTandas" disabled="disabled" id="fechaTandas" placeholder="seleccione una fecha">
 </div>

js

//JS to trigger the datepicker
$('#trigger-datepicker').datepicker({
     format: "yyyy/mm/dd",
    language: "es"    
});

This is the link to eternicodes datepicker plugin:

http://eternicode.github.io/bootstrap-datepicker

1 Answer 1

1

I think you need to handle the DatePicker's change event..

  $('#trigger-datepicker').datepicker()
    .on("changeDate", function(e){

      $('#fechaTandas').prop('disabled',false);
      $('#fechaTandas').val(e.format('yyyy/mm/dd'));
      $('#fechaTandas').prop('disabled',true);

  });

Demo: http://bootply.com/88516

1
  • Thank you very much! It worked as intended. I have no idea why the language doesn't change to spanish since the client for this is a spanish speaking company, but I'll have to see that later. Oct 18, 2013 at 13:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.