bootstrap-form icon indicating copy to clipboard operation
bootstrap-form copied to clipboard

old value on a BootForm::date

Open alifoz opened this issue 7 years ago • 6 comments

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 ?

alifoz avatar Mar 24 '17 14:03 alifoz

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?

dwightwatson avatar Mar 26 '17 01:03 dwightwatson

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

        <div class="form-group form-group-sm">

            {!! BootForm::open(['model' => $history, 'store' => 'history.store', 'update' => 'history.update']) !!}

            {!! BootForm::vertical() !!}


            <div class="col-xs-8">

                {!! BootForm::select('device_id',' Device ',$devices,old('device_id'),['class' => 'form-control']) !!}

            </div>


            <div class="col-xs-8">

                {!! BootForm::date('datetime','Date',old('datetime')) !!}
            </div>



            <div class="col-xs-8">
                {!! BootForm::textarea('details','Notes') !!}
            </div>



            <div class="col-xs-10">
                {!! BootForm::submit('Save') !!}
            </div>

            {!! BootForm::close() !!}

        </div>

In this situation , everything work well.

  1. 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"

]

alifoz avatar Mar 29 '17 12:03 alifoz

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

dwightwatson avatar Mar 29 '17 12:03 dwightwatson

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...

alifoz avatar Mar 29 '17 12:03 alifoz

@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 😄

SagarNaliyapara avatar Jul 31 '17 06:07 SagarNaliyapara

thank's

alifoz avatar Aug 10 '17 17:08 alifoz