Laravel-Backpack / addons

A place for the Backpack community to talk about possible Backpack add-ons.
5 stars 2 forks source link

[Addon Request] Form Builder / Quiz Builder #3

Open gvinson opened 4 years ago

gvinson commented 4 years ago

Feature Request

Ability to dynamically add fields to a CRUD view

What's the feature you think Backpack should have?

On the create/edit views, users would be able to dynamically add fields/sections to their form. They would be able to click a "Add" button that would let them select from a list of available form fields. After selecting one, the code would inject that field and all its required dependencies into the UI.

Have you already implemented a prototype solution, for your own project?

We have been working on it but since it uses the @push for scripts needed for each field, those JS scripts are not available when dynamically adding new fields. For example, if we started with a form that had a single input but wanted to add a CKEdtiro field, as of now, the ckeditor.js file/config will not have been loaded due to the way blade renders/uses stacks.

Do you see this as a core feature or an add-on?

I definitely see this as a core feature.

welcome[bot] commented 4 years ago

Hello there! Thanks for opening your first issue on this repo!

Just a heads-up: Here at Backpack we use Github Issues only for tracking bugs. Talk about new features is also acceptable. This helps a lot in keeping our focus on improving Backpack. If you issue is not a bug/feature, please help us out by closing the issue yourself and posting in the appropriate medium (see below). If you're not sure where it fits, it's ok, a community member will probably reply to help you with that.

Backpack communication channels:

Please keep in mind Backpack offers no official / paid support. Whatever help you receive here, on Gitter, Slack or Stackoverflow is thanks to our awesome awesome community members, who give up some of their time to help their peers. If you want to join our community, just start pitching in. We take pride in being a welcoming bunch.

Thank you!

-- Justin Case The Backpack Robot

pxpm commented 4 years ago

Hum .. hello @gvinson thanks for the suggestion.

But pratically what would be the application ?

From my understanding of your issue I can see this beeing something along the inline create, atleast the implementation.

User clicks a button, an ajax request is made to get the available fields, user select the field and another ajax request is done to pick the field definition. This last gets you the field html (including the scripts and styles) you can then add it to the DOM.

About the request part, maybe create an Operation that setups the routes and handle the available fields and the return of html .

I saw one of this days someone talking about something similar, like having "pre forms" made, and when you select the type of the form you want you get a different form. Dunno if you are trying to achieve the same. It's is somewhere around here in github, but i cannot find the issue/pr now.

spaznuski commented 4 years ago

So I am working on a similar concept for a project I am converting from Codeigniter to Laravel using backpack. In the Codeigniter version I had a form which allowed the user to select an option from a select list (dropdown) and it would insert additional form fields in DOM.

The Laravel (Backpack) version is done by using a custom select2 form field copied from backpack and adding some jscript to insert the info into the DOM. e.g $('#{{ $field['name'] }}').change(function() { var val = this.value; // value of the select element if (val != '') { $('#load_activity').load('{{ backpack_url('BACKPACK_CONTROLLER/ACTION') }}/' + val); } });

Now where I am stuck is I want to use another backpack field as the response from the call to action in the controller. So I copied and edited the table form field but I am still working out how to pass the required data so it can be loaded in the DOM.

So I want the function to be able to return the custom backpack form field view that can be inserted, not sure if that is possible. my function so far looks like this. echo view('vendor.backpack.crud.fields.custom_table')->render();

tabacitu commented 4 years ago

Hi guys,

This sounds cool - it really does, but I think it's out of scope for Backpack's core. It sounds to me like it'd make a really cool add-on though. So I'm going to move this issue to backpack/addons to talk this through.

Let me rephrase what you said, and in the process explain how I see it:

Anyway, I'm happy to see this issue. It's something I've always thought would be A LOT easier to build using Backpack than with anything else. If any of you have thoughts or code on this please share, I think it's something that would be very cool to have.

Cheers!

PS. Also let me know if I've misunderstood the issue at hand - it happens sometimes, that's why I like to rephrase 😆