dwightwatson / bootstrap-form

Bootstrap 3 form builder for Laravel
MIT License
217 stars 133 forks source link

old value on a BootForm::date #83

Open alifoz opened 7 years ago

alifoz commented 7 years ago

Hi! I have problems with:

{!! BootForm::date('datetime','Date' }

{!! BootForm::date('datetime','Date',old('datetime') }

This code not working, all the times the view show me a blank field datatime. (In the database, datetime field has a value, and when i change, this code not fill the field with the old value for the field 'datetime'.)

Can you Help me ?

dwightwatson commented 7 years ago

Happy to take a look into this one, but I think we're going to need a little more of your code to work out what is going on.

In addition, can you confirm that value of old('datetime') when you pass it into the method?

alifoz commented 7 years ago

Thank's. Let's the code...

1) I have a method create in controller

public function create($id){

    $history = new History;

    $devices = DB::table('devices')
                ->join('models','models.id_model','=','devices.model_id')
                ->where('id_device', '=', $id)
                ->orderBy('models.model_name','asc')->pluck('models.model_name','devices.id_device');

    return view('deviceapp.history.history',['history'=> $history,'devices' => $devices ]);

}

and my view is

{!! BootForm::open(['model' => $history, 'store' => 'history.store', 'update' => 'history.update']) !!} {!! BootForm::vertical() !!}
{!! BootForm::select('device_id',' Device ',$devices,old('device_id'),['class' => 'form-control']) !!}
{!! BootForm::date('datetime','Date',old('datetime')) !!}
{!! BootForm::textarea('details','Notes') !!}
{!! BootForm::submit('Save') !!}
{!! BootForm::close() !!}
In this situation , everything work well. 2) i have method edit public function edit($id){ $history = History::find($id); $devices = DB::table('devices') ->join('models','models.id_model','=','devices.model_id') ->orderBy('models.model_name','asc')->pluck('models.model_name','devices.id_device'); return view('deviceapp.history.history',['history'=>$history, 'devices' => $devices, 'id_history'=>$history->id_history ]); } and I use the same view that method create / edit. Here is my problem: When I edit, I would like that in the field date, load the old value of the datetime field ... Here is the value the object $history in my method "edit" "id_history" => 1 "device_id" => 1 "user_id" => 1 "datetime" => "2017-03-28 00:00:00" "details" => "Something" "created_at" => "2017-03-28 17:43:43" "updated_at" => "2017-03-28 17:43:43" ]
dwightwatson commented 7 years ago

Why are you providing old('x') to each field, isn't that handled for you already by the library?

alifoz commented 7 years ago

For someone fields the library work well, for another don't work.. For example...

this worked:

BootForm::textarea('details','Notes')

this didn't work:

BootForm::date('datetime','Date')

Because this, I tried to pass the old('x') ... BootForm::date('datetime','Date',old('datetime'))

but didn't work...

SagarNaliyapara commented 7 years ago

@alifoz BootForm::date('datetime','Date', $history->datetime) this will work for you i have same problem in date but at time of edit i have to pass data in date field only otherwise model binds data 😄

alifoz commented 7 years ago

thank's