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

Allow passing arbitrary form attributes #336

Merged
merged 1 commit into from
Dec 1, 2020

Conversation

drzraf
Copy link
Contributor

@drzraf drzraf commented Apr 18, 2019

Form support for data-*or config-data-*@ parameters to be used as <form> attributes

See #173 and #293 and #294

@drzraf
Copy link
Contributor Author

drzraf commented Jun 4, 2019

ping

@drzraf drzraf force-pushed the form-attr-improvments branch from be495ef to d83422d Compare July 3, 2019 14:26
@drzraf
Copy link
Contributor Author

drzraf commented Jul 3, 2019

rebased...

templates/forms/default/form.html.twig Outdated Show resolved Hide resolved
Copy link
Member

@mahagr mahagr left a comment

Choose a reason for hiding this comment

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

Some suggestions above.

@rhukster rhukster requested a review from w00fz July 12, 2019 17:24
@mahagr
Copy link
Member

mahagr commented Jul 15, 2019

@drzraf We were talking about the forms today, and it looks like there's already an implementation for this for form fields, which is different to your implementation. I think it would be great if both the form and the fields used the same way instead of needing very different input from each other.

This is the code for a form field:
https://github.com/getgrav/grav-plugin-form/blob/develop/templates/forms/default/field.html.twig#L106-L110

PS: There is also support for custom attributes, but it uses yet another approach:
https://github.com/getgrav/grav-plugin-form/blob/develop/templates/forms/default/field.html.twig#L97-L101

@drzraf
Copy link
Contributor Author

drzraf commented Aug 14, 2019

In order to move on, which implementation you advise?

@mahagr
Copy link
Member

mahagr commented Aug 14, 2019

@rhukster We need to decide how to define attributes throughout Grav. I kind of like field.attributes approach the best:

{% if field.attributes is defined %}
  {% for attribute in field.attributes %}
    {{ attribute.name }}="{{ attribute.value|e }}"
  {% endfor %}
{% endif %}

@drzraf drzraf force-pushed the form-attr-improvments branch from b3cf2ea to 2807d09 Compare December 10, 2019 13:38
@drzraf drzraf changed the title Form attr improvments Allow passing arbitrary form attributes Dec 10, 2019
@drzraf
Copy link
Contributor Author

drzraf commented Jan 1, 2020

Please see latest version:

Contrary to the previous form.data.blueprints.form extraction model, blueprints-expansion is not enabled.

Eg: data-data-foo@: '\Grav\Plugin\Admin::route' would not create a data-foo='http://...' attribute.

I'd be happy if you could help getting the best of both approaches.

@mahagr
Copy link
Member

mahagr commented Jan 2, 2020

IMHO data-*@ should work everywhere, so you can put it under attributes.

@drzraf
Copy link
Contributor Author

drzraf commented Jan 3, 2020

I strongly share that wish, but I simply failed to find a way to do it.

Contrary to the previous `form.data.blueprints.form` extraction model,
blueprints-expansion is not enabled.

Eg: `data-data-foo@: '\Grav\Plugin\Admin::route'` would *not* create
 a `data-foo='http://...'` attribute.
@drzraf drzraf force-pushed the form-attr-improvments branch from 2807d09 to 8736f0b Compare June 16, 2020 18:25
@rhukster rhukster merged commit e4486d5 into getgrav:develop Dec 1, 2020
@drzraf
Copy link
Contributor Author

drzraf commented Dec 1, 2020

@rhukster : I'm really happy this got merged.
Still, I wonder: Didn't you encountered an option also preserving the blueprints-expansion feature?

@NicoHood
Copy link
Contributor

NicoHood commented Dec 1, 2020

@drzraf From my understanding data-attributes@: '\Grav\Plugin\Admin::route'.

It is documented here:
https://learn.getgrav.org/16/forms/blueprints/advanced-features#using-function-calls-data-at

I think the function must return a named array (dict) so we have attribute name -> value. The example uses '\Grav\Common\Page\Pages::parentsRawRoutes' maybe try this as a first test?

This new feature should be documented here:
https://learn.getgrav.org/16/forms/forms/fields-available

@NicoHood
Copy link
Contributor

@drzraf did that work?

@drzraf
Copy link
Contributor Author

drzraf commented Dec 30, 2021

Sadly no. Not with the merged commit,

  1. Attributes are duplicated. Output from the form.attributes loop, then with the blueprints.form.attributes loop
  2. These attributes are not expandable (no @ suffixing)

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

Successfully merging this pull request may close these issues.

4 participants