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

Discuss - valid HTML #433

Closed
ianhobbs opened this issue Apr 28, 2020 · 17 comments
Closed

Discuss - valid HTML #433

ianhobbs opened this issue Apr 28, 2020 · 17 comments

Comments

@ianhobbs
Copy link

ianhobbs commented Apr 28, 2020

Hi This is more of a discussion of good form.
Html validation throws errors on a lot of the Alpine markup. [ x-data , @click, :class etc ] . I'm using the following Doctype declarations.

<!DOCTYPE html> <html lang="en"> <meta charset="UTF-8">

Is there an advisory on a better doctype declaration to allow these attributes?

There is no fuctional error just a validation error.

@SimoTod
Copy link
Collaborator

SimoTod commented Apr 29, 2020

I don't think there are any doctypes supporting x-* attributes but browser will still render the page even with "invalid" attributes.
Does it cause a particular issue?

@MuzafferDede
Copy link
Contributor

MuzafferDede commented Apr 29, 2020

I used to challenge this a lot back in time. I was building front end of airline company's website which they need to be valid by W3C and WCAG guidelines and validators. So i couldn't use custom attributes or anything that cause red flag on the validation.

This wonders me if that is the case, could we go with data-x-[directive]. Also I was thinking x- attribute should be configurable so devs can define their own selectors. Maybe something like data-alpine-config="{prefix: 'data-x'}" so with this, alpine directives will regionesed by data-x-[directive] prefix.

@SimoTod
Copy link
Collaborator

SimoTod commented Apr 29, 2020

I think we can easily support an extended syntax data-x-* along the canonical one for those who need to stick with valid html5 syntax if Caleb is cool with that.
It will be just about adding an optional data- prefix to the regexps.

@HugoDF
Copy link
Contributor

HugoDF commented Apr 29, 2020

I agree with adding support for "data-x-" on top of "x-" (rather than config).

In a way I'm sure it could just be a "alpine-w3c-compliant" fork since the changes are likely to be very localised

@calebporzio
Copy link
Collaborator

I think we should hold off on this until it's a legitimate problem for people.

Not worth the work of no one actually needs it

@ntkoopman
Copy link

I think it would be good to have an alternative. I was thinking of using alpine together with server rendered react, but jsx doesn't support non-valid attributes like @click, so it's impossible.

@ntkoopman
Copy link

Oh, seems it's already there using x-on: and x-bind: instead which work correctly in react as well (might have to use object spread when using jsx, like <div x-on:click="open=false" {...{'x-show.transition.out':'open'}}>)

@vrabota
Copy link

vrabota commented Sep 24, 2021

Any news on this item? I can't upload my premium theme on Envato platform because of this issue :(

@SimoTod
Copy link
Collaborator

SimoTod commented Sep 24, 2021

@vrabote V3 supports custom prefixes: #2042 (comment)

@vrabota
Copy link

vrabota commented Sep 24, 2021

@SimoTod Thank you!!! It's will be nice to have that in docs 👍

@calebporzio
Copy link
Collaborator

@vrabota - good call. Can you PR documentation for it? Thanks!

@driss-chelouati
Copy link

driss-chelouati commented Sep 26, 2021

@calebporzio I implemented a solution proposed by @SimoTod , but it does only partially work and doesn't pass validation. This is my entire alpine setup:

//Alpine JS and plugins import
import Alpine from 'alpinejs'
import intersect from '@alpinejs/intersect'
import Fern from '@ryangjchandler/fern'
//Prefix alpine special attributes to pass W3C validation
document.addEventListener('alpine:init', () => Alpine.prefix('data-x-'))
window.Alpine = Alpine
//Init intersect plugin
Alpine.plugin(intersect)
//Init Fern plugin
Alpine.plugin(Fern)
//Init Fern persisted store
Alpine.persistedStore('app', {
    isLoggedIn: false,
})
//Start Alpine JS
Alpine.start()

Unfortunately, this also prevents me from releasing this product on ThemeForest.

Using data-x-* attributes, I don't have the invalid attributes errors of before. But now I have XML errors. So Iam affraid this isn't solved yet or Iam missing something. See attached screen.
alpine-w3c

@vrabota
Copy link

vrabota commented Sep 28, 2021

@driss-chelouati you can't use custom data-* attributes with data-x-on:click (it's not allowed), should be something like data-x-on-click.
: is not allowed in data-* attributes, can we have this stuff configurable as well?

@vrabota
Copy link

vrabota commented Sep 28, 2021

@driss-chelouati you can fix your issues by using this approach https://alpinejs.dev/globals/alpine-data#encapsulating-directives-with-x-bind

Instead of defining your custom directives like x-bind:class you can use in HTML just x-bind="trigger" that encapsulate all not allowed tags

@driss-chelouati
Copy link

@vrabota That would only result in unecessary convolutions in my code as it does not fit my use case. I simply need to use existing directives or otherwise why are they still there if they do not validate? In the end, I'll just end up converting my stuff to Vue and dropping alpine for good as I don't see a fix coming for this in a reasonable delay.

@PubliAlex
Copy link

@driss-chelouati you can fix your issues by using this approach https://alpinejs.dev/globals/alpine-data#encapsulating-directives-with-x-bind

Instead of defining your custom directives like x-bind:class you can use in HTML just x-bind="trigger" that encapsulate all not allowed tags

That's not a viable solution, it completely change most developper workflow whereas we just need a syntax that would be w3c valid.

@SimoTod
Copy link
Collaborator

SimoTod commented Jun 11, 2024

@PubliAlex This is probably your best shot: #3397

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

9 participants