adamwathan / form

Super basic form HTML builder, only really exists so I can pull it in for some other more useful projects.
MIT License
232 stars 117 forks source link

Bind translated name groups #116

Open elephantux opened 7 years ago

elephantux commented 7 years ago

I use dimsav/laravel-translatable with adamwathan/form. In this part of code BootForm::bind($model) does not work:

{!! BootForm::open()->action( route('catalogs.update', $catalog) )->put() !!}
{!! BootForm::bind($catalog) !!}
@foreach($locales AS $locale => $localeData)
    {!! BootForm::text('Title', $locale.'[title]') !!}
@endforeach
{!! BootForm::close() !!}

I found only one solution but it is not pretty good:

{!! BootForm::text('Title', $locale.'[title]')->value(isset($catalog->translate($locale)->title)?$catalog->translate($locale)->title:'') !!}

Any ideas why bind don't work on this?

jesseleite commented 7 years ago

Rather than binding the actual model, you could bind an array of translated attributes. I'm not familiar with dimsav/laravel-translatable, but is something like this possible?

BootForm::bind($catalog->translate($locale)->getAttributes())

If not, you might need to map your own array of translated attributes, and send that mapping to your view. Or inject a view service to do that work right from the view. Nawmean?