问题
I'm using Laravel PHP Framework with Bootstrap. I want to know how to insert a datepicker in to a form.
I already have the bootstrap-datepicker installed but do not know how I will use.
Here is the code of my form:
{{ Form::open(array('action' => 'HomeController@postRegister')) }}
<p>{{ Form::text('first_name', '', array('class' => 'form-control','placeholder' => 'primeiro nome')) }}</p>
<p>{{ Form::text('last_name', '', array('class' => 'form-control','placeholder' => 'último nome')) }}</p>
<p>{{ Form::text('email', '', array('class' => 'form-control','placeholder' => 'email')) }}</p>
<p>{{ Form::text('phone_number', '', array('class' => 'form-control','placeholder' => 'o teu número de telemóvel')) }}</p>
**<p>{{ Form::text('date_of_birth', '', array('class' => 'form-control','placeholder' => 'a tua data de nascimento')) }}</p>**
<p>{{ Form::password('password', array('class' => 'form-control','placeholder' => 'a tua palavra-passe')) }}</p>
<p>{{ Form::password('password', array('class' => 'form-control','placeholder' => 'reintroduzir palavra-passe')) }}</p>
<p>{{ Form::submit('regista-te', array('class' => 'btn btn-danger')) }}</p>
{{ Form::close() }}
I need to replace this code for a datepicker:
<p>{{ Form::text('date_of_birth', '', array('class' => 'form-control','placeholder' => 'a tua data de nascimento')) }}</p>
Like this:
As a componet:

I hope someone can help me :)
Thanks!
回答1:
Twitter bootstrap uses
data-datepicker="datepicker"
to show the date picker. Laravel will allow you to use this is the same array as the class and placeholder.
<p>{{ Form::text('date_of_birth', '', array('class' => 'form-control','placeholder' => 'a tua data de nascimento','data-datepicker' => 'datepicker')) }}</p>
回答2:
The following has worked for me. Difference between @Marco's and my answer is data-provide instead of data-datepicker.
{{ Form::text('startingDate', null, array('class' => 'form-control input-sm','placeholder' => 'Starting Date','data-provide' => 'datepicker')) }}
来源:https://stackoverflow.com/questions/20272257/laravel-4-with-bootstrap-datepicker