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

HTML5 custom hyphenated attribute #807

Closed
cuihq opened this issue Apr 13, 2018 · 1 comment
Closed

HTML5 custom hyphenated attribute #807

cuihq opened this issue Apr 13, 2018 · 1 comment

Comments

@cuihq
Copy link

cuihq commented Apr 13, 2018

Issues:

slim code:

div data={object_id: 1}

html expect:

<div data-object_id="1"></div>

html actual:

<div data-object-id="1"></div>

Reason:

The custom attributes are all underscore.
Do not need to switch between underscore and dasherize (camelize).
So compatibility is better.

  • compatible with ruby
{object_id: 1} # not {'object-id' => 1} or {objectId: 1}
  • compatible with javascript/coffeescript
element.dataset.object_id // not element.dataset.objectId
  • compatible whit jQuery
$(element).data('object_id') // not $(element).data('objectId')

Validate:

validate attribute data-object_id:

Code:

hyphen_attr("#{name}-#{n.to_s.gsub('_', '-')}", escape, v)

modified code:

hyphen_attr("#{name}-#{n}", escape, v)

Test:

Test code that needs to be changed:

def test_hyphenated_attribute

stonean pushed a commit that referenced this issue Jul 14, 2018
@stonean stonean closed this as completed Jul 14, 2018
stonean pushed a commit that referenced this issue Jul 14, 2018
aliuk2012 added a commit to ministryofjustice/correspondence_tool_staff that referenced this issue Oct 11, 2018
Users reported that they were not able to upload files. What was happening
is that dropzone was not displaying the filename and file size for the file
that was uploaded. The cause of this issue was from us recently updating
slim-rails and slim changed the way html data attributes were output. This
meant that dropzoneJS could not find the right attributes to update and
display.

slim-template/slim#807
slim-template/slim#820 someone else reported
this issue to slim and suggested adding a configuration option to allow
underscore to hyphen conversion to still take place.

This commit updates dropzoneJS to the latest version.
@atiqueakhtar
Copy link

atiqueakhtar commented Dec 2, 2022

Hi @cuihq @stonean In my app I found out that the changes are working as expected for simple HTML tags where we use data attributes like this - data = {first_name: 'Stephen'} and not data: {first_name: 'Stephen'} but in form helpers like simple_form_for where we use them strictly as data: { disable_with: 'One Moment' }, the expected change of data-disable_with="One Moment" is not observed.

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

No branches or pull requests

3 participants