-
Notifications
You must be signed in to change notification settings - Fork 920
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[4.1][Feature][Beta] Repeatable field type (aka matrix; aka group) #2266
Conversation
Since you can use ALL Backpack field types with this field, it needs extensive testing before it's merged and launched. The testing list should include:
The following advanced use cases should be tested and documented:
|
🙌🏼 Image uploaders I’ve found to be the hardest thing for these field types, have you sorted those all okay? |
how is the Select2_multiple (n-n relationship with pivot table) supposed to work in here?
|
It will released also in the 3.6 version ? Or only 4.0 ? |
@OwenMelbz indeed image uploaders are a bit tricky. I'm on it. @annadnl I think each
Is this what you were asking? I think that's the intuitive way to see it. Don't know about the pivot table though - since most of the time the value of the input won't actually be stored as a column in the DB, but as an attribute in a JSON column, that's the use case I think we should prioritise - storing the value as a JSON. @diakosavvasn It'll only be available in v4. We've made considerable changes to ALL fields from v3 to v4, specifically to allow us to create a field like this one. In v3 it's "very very VERY" difficult to do. In v4 it's just "very" difficult 😄 |
Definitely looking forward to this field! Though I wonder if the fields can be vertically stacked instead of horizontal |
@ziming Yes, they're vertically stacked by default - they work exactly the same as Backpack fields inside a create/update operation. You can make more fields fit into one line using But by default, with no |
I get that we can save the data in a different way, but can the data be fetched in a different way too if we don't save it directly to a json column? |
@ziming sure. If you use an Accessor and a Mutator. So on the model you can have: public function getRepeatableAttribute() {
// fetch it any way you want
// but it'll have to be a JSON or PHP array when you return it
}
public function setRepeatableAttribute($value) {
// store it any way you want
} |
Nice, I thought about using the 'default' key initially but yours was a better way. Shall try this field in 1 of my apps and feedback here on how it goes |
Just used it for a test run today with 3 number fields. All of them get saved as strings inside the json array in the end. Wonder if there is an easy way to ensure if the type is number, it gets saved as a number in the json. I could intercept it at update() or set attribute method but if the field auto cast it based on the sub field type, that might be great |
@ziming indeed that would be nice. I'm wondering if it's an optimization worth doing. Do you see any other fields apart from If the "number" field would be only one to use this, I don't think it's worth doing - it would overcomplicate the logic for all fields, when it's easy to fix on the developer side (just cast it in PHP before echoing or using). |
Wow! |
found something i need in this moment: reorder the item is missing too, i want the second item to be the first for example, and it is missing |
Sorting (sortable) would be nice to have feature. |
#2711 enjoy :) Thanks for pitching in 👍 |
When you included multiple fields of this type, using Javascript instead of PHP (for ex inside the repeatable field type), the cropper always showed the preview of the first element, instead of each instance of the field having its own preview area. This fixes that by making the selector use classes instead of IDs.
…tency between them Also removed one place where base64_image was using ID instead of class.
That way the IDs are different if multiple checkboxes with the same name are on the same page (for example inside a repeatable field).
…input instead of multiple inputs
…ype; makes sure that init functions are only called once per element;
Addresses #2266 . The checklist field now loads its options using PHP, but it checks those options using JavaScript. The value of the field is now stored in a hidden input, instead of individual checkboxes like it was doing before. The syncPivot() method has been amended to also support passing the connected entries as a JSON, not only a direct array. This was done because when storing multiple values inside one hidden input, the value that reaches PHP is a JSON. But previously, when there were individual inputs for each value, the value that reached PHP was a PHP array. This is a non-breaking change, and I expect it will also help with other fields - if we wish to store multiple IDs inside one hidden field.
Also adds select2_nested example inside MonsterCrudController.
So it's an amazing field but i had issue with image field as @joaojoyce Image Setter same as documentation with some comments to serve my need Images saved in database like that And also uploaded and saved to my disk correctly Hope it helps someone and hope it make sense for you @joaojoyce |
Update - Pedro has just finished refactoring the This refactor also opens up the possibility for us to maybe make I've decided to create one issue for all things |
As talked about in #131, #771 . I think now that v4 allows us to reinitialize fields with Javascript, it's finally its time to shine.
Repeatable
Allows the developer to add a group of Backpack fields (ex: 1 text field, 2 browse fields, 1 wysiwyg field). The user can fill in the fields, add another group with the same fields, or delete groups.
Screenshot:

Syntax:
By default it compacts the fields and stores the group of fields as JSON. But the saving can be intercepted in the create/update operation, or using a mutator on the model, to make it store the values in a different way.