Skip to content
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

[POC][WIP] add CrudField function to get all fields on page - crud.allFields() #4962

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tabacitu
Copy link
Member

@tabacitu tabacitu commented Mar 5, 2023

WHY

BEFORE - What was wrong? What was happening before this PR?

When working on Laravel-Backpack/community-forum#206 (comment) I realised
we have no way of getting ALL fields on page.

AFTER - What is happening after this PR?

We do, we have crud.allFields() which returns the same as if you passed an array with all the fields you want to crud.fields()

HOW

How did you achieve that, in technical terms?

jQuery, but should be refactored to JS if we decide to do it.

Is it a breaking change?

Non-breaking.

How can we test the before & after?

Inside any CRUD Create/Update operation, you can do

  • crud.allFields() to select all fields;
  • crud.allFields().forEach(field => { field.hide(); }); to hide all fields in a form;

@tabacitu tabacitu changed the title add CrudField function to get all fields on page - crud.allFields() [POC][WIP] add CrudField function to get all fields on page - crud.allFields() Mar 5, 2023
@tabacitu
Copy link
Member Author

tabacitu commented Mar 5, 2023

What do you think @pxpm ... should we do this?! 🤷‍♂️

One thing that makes me say "yes" is that even us, in the demo, we have a place where we MANUALLY specify all fields in Monster. To then target them using the hide/show/disable/enable buttons in FieldMonsters. So... we did have the need for this... but didn't fix it by adding to the API.

@scrutinizer-notifier
Copy link

The inspection completed: No new issues

@pxpm
Copy link
Contributor

pxpm commented Mar 7, 2023

Hey Cristian, I think this is a good addition.

I've only a few questions/concerns.

a) When the script fails to find a matching input, it still adds the CrudField object in the array of found fields (but without the input)
image

image

I think we should remove CrudField objects that has no input defined after the search from the final array, we already show a console error when we fail to identify then.

b) do we really need the form in the field selector ? I don't think bp-field-name is used anywhere else or makes sense to use as anything else than a field name identifier.
We could use form as a parameter to support multiple forms, but in case of multiple forms, using form in the selector or not using it at all will make no distinction between forms anyway, both are form elements.

c) at the moment this does not target subfields. Is this intended ? Is there any scenario where we need to get all fields with subfields included? I don't think it's necessary when talking about hide, show etc, as if you hide the parent you hide the subfields too. I think it's ok to don't target subfields by default, just want to note it here to make sure we don't miss use-cases.

Cheers

@pxpm pxpm assigned tabacitu and unassigned pxpm Mar 7, 2023
@realtebo
Copy link
Contributor

realtebo commented Aug 24, 2023

We'd love to have this feature. thanks for working on it !

I kindly suggest a way to retrieve not all fields but an object with all field names and their values.
so we can easily pass all forms value to eventually ajax post

@pxpm
Copy link
Contributor

pxpm commented Aug 24, 2023

We'd love to have this feature. thanks for working on it !

I kindly suggest a way to retrieve not all fields but an object with all field names and their values. so we can easily pass all forms value to eventually ajax post

Hey @realtebo I like this feature too. We may revive this soon 🙏

Regarding sending the form values, you can already serialize a form to array.

We also have an helper that helps (who would have guessed? 🙃 ) on "arranging" that form data, that we use on the select2_ajax functionality:

function backpack_form_input()

So when you send the request to use that helper, just make sure you send your serialized form data inside the form key in the request.

I've given you an example in Laravel-Backpack/community-forum#646 (comment)

Cheers

@realtebo
Copy link
Contributor

backpack_form_input

This function helps for php-side. I mean for js side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

4 participants