Skip to content

Conversation

@jrushlow
Copy link
Collaborator

fixes #118

@jrushlow
Copy link
Collaborator Author

related tests pass - failures related to deprecation that is fixed in #122

'dataOrControllerName' => 'false-controller',
'controllerValues' => ['isEnabled' => false],
'expected' => 'data-controller="false-controller"',
];
Copy link
Member

Choose a reason for hiding this comment

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

I did some more digging into this... and I think my proposed solution (which you implemented perfectly) is not... perfect ;).

For this test case:

<!-- current output -->
<div
    data-controller="false-controller"
    data-false-controller-is-enabled-value=""
>

The ="" for a false value is the problem. It should be ="false", which I've determined DOES cause the value in the controller to be false. Similarly, for true, the attribute should be ="true". Additionally, omitting the attribute entirely would cause this.hasIsEnabledValue (you can use a "hasser" like this to check for the existence of a value) to incorrectly return false with this current PR.

So I think the fix is to "fix" how we convert boolean values:

<!-- if isEnabled is passed as FALSE -->
<div
    data-controller="false-controller"
    data-false-controller-is-enabled-value="false"
>

<!-- if isEnabled is passed as TRUE -->
<div
    data-controller="false-controller"
    data-false-controller-is-enabled-value="true"
>

Copy link
Collaborator Author

@jrushlow jrushlow Apr 25, 2021

Choose a reason for hiding this comment

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

that make sense.. done. keeping this "unresolved" for future reference.

@jrushlow jrushlow force-pushed the fix/false-attribute branch 2 times, most recently from 242cabb to 1580cd8 Compare April 25, 2021 16:05
],
'controllerValues' => [],
'expected' => 'data-controller="my-controller" data-my-controller-boolean-value="1" data-my-controller-number-value="4" data-my-controller-string-value="str"',
'expected' => 'data-controller="my-controller" data-my-controller-boolean-value="true" data-my-controller-number-value="4" data-my-controller-string-value="str"',
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i've implemented (string) true|false for the rendered value. But this "breaks" the previous 1 === true output even though false was blank.

I personally prefer true|false over 1|0 as it's clear that the value is not intended to be an int / (string) number. But would this be considered BC even though the PR is intended to fix false bool's?

Copy link

Choose a reason for hiding this comment

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

Do not think this is a BC break, because one who defined a Stimulus value as Boolean, and the value was true-thy, having it previously rendered as ..-value="1", which in Stimulus was correctly interpreted as true.

And fixing that the false value was not being rendered as ..-value="false" means imo it's currently incorrect, and of course the exact purpose of your PR ;].

@hvt
Copy link

hvt commented Apr 26, 2021

Just hit this in my project, and wanted to let you know this PR fixed it for me :].

@jrushlow jrushlow changed the title [stimulus-controller] fix bool false attributes from being rendered [stimulus-controller] fix bool attributes from being rendered incorrectly Apr 26, 2021
@jrushlow
Copy link
Collaborator Author

Just hit this in my project, and wanted to let you know this PR fixed it for me :].

Awesome! That's good to hear - we should be able to get this pushed out pretty quickly.

@weaverryan weaverryan force-pushed the fix/false-attribute branch from 1580cd8 to 2694dca Compare April 26, 2021 12:48
@weaverryan
Copy link
Member

Thanks for the nice fix Jesse - and to @hvt also for double-checking it for us in a real app <3

@weaverryan weaverryan merged commit f282fb1 into symfony:main Apr 26, 2021
@jrushlow jrushlow deleted the fix/false-attribute branch April 26, 2021 12:49
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.

stimulus_controller() improperly adds a value attribute when set to false

3 participants