Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[4.1] Fix repeatable fields initialization #3143

Closed
wants to merge 1 commit into from

Conversation

pxpm
Copy link
Contributor

@pxpm pxpm commented Aug 22, 2020

refs: #3141 , #3137

Adds a new class to identify the repeatable fields.

Using the data-repeatable-input-name does not work because repeatable fields initialization is after we need it.

Excludes the repeatable fields from initialization if the selector is not a repeatable-element container.

more info: #3141 (comment)

@scrutinizer-notifier
Copy link

The inspection completed: No new issues


// If it's not a repeatable container we exclude all the repeatable fields from the initialization
if (!selector.hasClass('repeatable-element')) {
$elements = $elements.not(".repeatable-field-input");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pxpm this would set a bad precedent - I'd rather avoid having hardcoded stuff about one field inside form_content.blade.php. This file is general, for all fields, so it should not do things differently depending on field type. If we hardcode stuff about repeatable today, we'll hardcode stuff about another field tomorrow, and soon enough it's all a jumbled mess and the form depends a bunch of fields.

Plus, what would have happened if repeatable was an addon, and it didn't have the possibility to modify form_content at all?

What other solution can we find that keeps the changes in repeatable.blade.php alone?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @tabacitu atm I could not think of any other solution, but maybe this is a wording problem that we can fix.

First of all, why the change in form_content: there are three places in the current code where we call initializeFieldsWithJavascript.

The ones we are looking for are the self form_content that initializes the whole form, and the repeatable call that would initialize the repeatable elements.

What is needed here is a way to NOT initialize some fields per developer instruction. Atm there is no functionality in backpack that allows this. It's here that I say this might be a wording problem.

If we changed the classe names from: repeatable-element to self-initialize-container and repeatable-field-input to self-initialize-field we are creating a feature that other developers could use to tell backpack that the fields inside that container should not be initialized by main form initialization script and that would make repeatable use that functionality instead of being "a repeatable functionality". That's what I would call the wording problem.

Let me know what you think.

Pedro

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That. Is fucking. AWESOME! Excellent solution @pxpm , and excellent wording for it.

Do we need to rename repeatable-element and repeatable-field-input or can we just add this feature on top? Aren't repeatable-element and repeatable-field-input used for other purposes, other than initialising the JS?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

repeatable-element is already used by repeatable functionality, we can add the self-initialize-container class along with. As for repeatable-field-input that's a class I created for this functionality, so it could just be renamed to self-initialize-field.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pxpm we decided in our conversation that we should try to move ALL subfields outside the main form, using @push('before_scripts') or something like that. If that happens we'll no longer have that problem.

Waiting for your alternative PR with that solution - I have high hopes for it 😄

@pxpm
Copy link
Contributor Author

pxpm commented Aug 25, 2020

closed in favor of: #3148

@pxpm pxpm closed this Aug 25, 2020
@pxpm pxpm deleted the fix-repeatable-container-initalization branch August 25, 2020 11:07
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants