-
-
Notifications
You must be signed in to change notification settings - Fork 399
UX FormCollection #90
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
Changes from 1 commit
ae5d325
c305f0c
5e6dd84
eea2313
f651d90
cc02076
dceb2cf
dfb54f8
9300cda
ec4342a
b4f40cd
0584757
abd2b8f
3996f3b
aaa6811
4791ff9
8539ff9
2d1ed04
1e3105d
0a9cc54
94be94c
c805c0e
e56d04b
7467cee
a8c730c
ecd774a
25d8306
8e5cd8a
3b110f9
c36157c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -91,18 +91,14 @@ class BlogFormType extends AbstractType | |
| // ... | ||
| ->add('comments', UXCollectionType::class, [ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be as helpful as possible, I think we need to show the user a simple Overall, this is how my example looks locally - I think these options are helpful to all show! 'allow_add' => true,
'allow_delete' => true,
'entry_type' => FileType::class,
// ideally UXCollectionType can set this for us
'by_reference' => false,
'entry_options' => [
// hides the "0", "1", "2" labels on the embedded forms
'label' => false,
],
'button_add_options' => [
'label' => '<span class="fa fa-plus"></span>',
'label_html' => true,
'class' => 'btn btn-secondary btn-sm'
],
'button_delete_options' => [
'label' => '<span class="fa fa-times"></span>',
'label_html' => true,
'class' => 'btn btn-danger btn-sm'
], |
||
| // ... | ||
| 'button_add' => [ | ||
| // Default text for the add button (used by predefined theme) | ||
| 'text' => 'Add', | ||
| // Add HTML classes to the add button (used by predefined theme) | ||
| 'class' => 'btn btn-outline-primary' | ||
| ], | ||
| 'button_delete' => [ | ||
| // Default text for the delete button (used by predefined theme) | ||
| 'text' => 'Remove', | ||
| // Add HTML classes to the add button (used by predefined theme) | ||
| 'class' => 'btn btn-outline-secondary' | ||
| ], | ||
| // Default text for the add button (used by predefined theme) | ||
| 'button_add_text' => 'Add', | ||
| // Add HTML classes to the add button (used by predefined theme) | ||
| 'button_add_class' => 'btn btn-outline-primary', | ||
stakovicz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // Default text for the delete button (used by predefined theme) | ||
| 'button_delete_text' => 'Remove', | ||
| // Add HTML classes to the add button (used by predefined theme) | ||
| 'button_delete_class' => 'btn btn-outline-secondary', | ||
| ]) | ||
| // ... | ||
| ; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,14 @@ | ||
| {%- block button_add -%} | ||
| {%- set attrDataAction = (attr['data-action']|default('') ~ ' ' ~ controllerName ~ '#add')|trim -%} | ||
| <button data-action="{{ attrDataAction }}" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be better if we can use the exist Maybe we can use in the Form Builder the So we could go with: 'button_add_options => [
'label' => 'app.button_add',
'label_translation_parameters' => [],
'attr' => ['class' => '...']
],This make it possible to use any of the exist button options and would be easier for theming also for future themes.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea, this is interesting. To accomplish this, I think it would be very similar to how You can see how the Later, it's added as a view variable: https://github.com/symfony/symfony/blob/a05702965e9fc0de7ce77d1641e772e2fbfe9911/src/Symfony/Component/Form/Extension/Core/Type/CollectionType.php#L91-L101 It would be interesting to do the same thing with both buttons. We would pass |
||
| class="{{ button_add.class|default('') }}" type="button">{{ button_add.text|default('Add')|trans }}</button> | ||
| class="{{ button_add_class }}" type="button">{{ button_add_text|trans }}</button> | ||
| {%- endblock button_add -%} | ||
|
|
||
| {%- block button_delete -%} | ||
| {%- set attrDataAction = (attr['data-action']|default('') ~ ' ' ~ controllerName ~ '#delete')|trim -%} | ||
| <button data-action="{{ attrDataAction }}" | ||
| class="{{ button_delete.class|default('') }}" type="button"> | ||
| {{ button_delete.text|default('Remove')|trans }}</button> | ||
| class="{{ button_delete_class }}" type="button"> | ||
| {{ button_delete_text|trans }}</button> | ||
| {%- endblock button_delete -%} | ||
|
|
||
| {% block ux_collection_widget -%} | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd love to NOT need this block. Instead, inside of Even the I'm pushing for this because, if we accomplish this, then if the user has already customized their <div
{{ stimulus_controller('symfony/ux-form-collection/collection') }}
data-prototype="{{ form_row(form.files.vars.prototype)|e('html_attr') }}"
>
Files:
<button
class="btn btn-sm btn-secondary"
{{ stimulus_action('symfony/ux-form-collection/collection', 'add') }}
>+</button>
{% for fileForm in form.files %}
{{ form_row(fileForm) }}
{% endfor %}
</div>Currently that doesn't work because I have avoided rendering the EDIT: Hmm, I see that you will still need this block so that you can use the |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will renamed this key
button_add_attrto allow user to set multiple attributes to the Add button and use the attribute block available in the form_theme to build them. Same for thebutton_delete_classThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add support for arrays as well here: https://gist.github.com/ker0x/8a1bad79a22f0ebae9ddf28c264dd13f#file-enhancedcollectiontype-php-L42-L44
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed it's better, gist updated! Thanks 😉