laravel-form-builder icon indicating copy to clipboard operation
laravel-form-builder copied to clipboard

Enhancement Read Only as Form Static Inputs

Open rico opened this issue 9 years ago • 5 comments

Thanks for the package - love it so far. What I really would like to have, is a simple way to display a form with static inputs only (especially for the show method of a Route::resource).

I know that you just implemented disableFields() method. But in my opinion, static Bootstrap fields look just better than readonly inputs.

rico avatar Jun 22 '15 15:06 rico

I agree, but i didn't implement it (yet), because i don't know how show some fields as static, for example list of checkboxes (choice multiple expanded) or multiple select. Do you have any idea?

kristijanhusak avatar Jun 22 '15 15:06 kristijanhusak

Hi, thank you for the quick reply - and sorry it took me so long. However, happy to hear you agree on this :-)

I would suggest, for example, using Glyphicons for checkboxes (glyphicon-unchecked, glyphicon-check), together with List groups or normal Unordered lists to display checkboxes or multiple selections. I used such combinations in other projects and it looked quite good - imho.

I would do it as simple as possible, but give the user the ability to change the view in a custom template or templates (like the templates for the different inputs).

rico avatar Jun 24 '15 14:06 rico

@rico I'm not sure using glyphicons is good idea, because in that way i'm tight coupling the views to bootstrap only. Also, I'm thinking of creating separate class for this read only functionality, where you would pass form instance to it to get that behavior. I don't want to add too much responsibilites to the Form class, it has many already.

kristijanhusak avatar Jun 26 '15 08:06 kristijanhusak

@kristijanhusak - can't you couple the static views to the FormBuilder (or some other class) as you did with the existing inputs? If one uses your package out of the box, they are all coupled to Bootstrap by default anyway.

I completely understand your concern about not adding to much responsibilities to the Form class. However, from a developers perspective, I think it would be much more convenient to have a method on the Form class itself. Maybe you could separate the logic using a trait?

rico avatar Jun 26 '15 11:06 rico

Also, I'm thinking of creating separate class for this read only functionality, where you would pass form instance to it to get that behavior. I don't want to add too much responsibilites to the Form class, it has many already.

It would be nice to also have the ability to specify some fields as read-only / static. So I don't know if a separate class for the read-only functionality would be a good idea.

i don't know how show some fields as static, for example list of checkboxes (choice multiple expanded) or multiple select.

I'ld tackle this by having the option resolve to the value that is selected. So for instance, when there is a list (or multiselect list), just display the items that are selected. Checkboxes are a bit harder, I think. Maybe you can display the value? Or only display the field if it is checked?

I think it could be implemented in a way like this:

$form = $formBuilder->create(SongForm::class, [
    'method' => 'POST',
    'url' => route('song.store')
]);

$form->fix('name', 'My Song');

Or, when a model is provided

$form = $formBuilder->create(SongForm::class, [
    'method' => 'PUT',
    'model' => $my-song,
    'url' => route('song.store')
]);

$form->fix('name');

So the Form class could have a method fix that would replace a field (with for example text type) with a static field.

mitchellklijs avatar Jul 03 '18 10:07 mitchellklijs