Issue #943Opened March 9, 2018by nojacko0 reactions

[BUG]: Checkbox trait doesn't remove attribute when unchecked

Question

When html attributes are true or false, the should either exist or not exist.

For example, required. This don't have a value in HTML5.

  • Valid (not required):<input type="text">
  • Valid (required): <input type="text" required>
  • Invalid (not required):<input type="text" required="false">
  • Invalid (required):<input type="text" required="true">

When the HTML grapes is then rendered outside Grapes and the input is checked if it's required, this fails as Chrome always returns true is the required attributes is set... regardless of the value.

I've been looking into this myself but not figure it out yet but it looks like Components needs a removeAttribute function to handle this.

Sorry, but in a rush, so I'll provide fiddle on Monday...

Answers (3)

nojackoMarch 12, 20180 reactions

@artf Thanks for the quick solution but it doesn't appear to work. Both inspecting the Grapes source and calling getHtml() return required="true" and required="false". I'm guessing because the attribute is a boolean value represented as a string.

I will where I can but, unfortunately, I'm on an unusual tight schedule for the GDPR rules coming in.

mikereemMay 2, 20190 reactions

I think commit 9a71368 is not enough. It writes boolean attributes without their values to the html output fine. But when the output is read again by the editor, then the boolean attributes are not initialized. If the boolean attribute was shown in the html (which means the value is true), then the editor initializes this attribute with value: "" and not true.

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.