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

Treat attribtues set with boolean values as properties #21

Merged
merged 1 commit into from
Jan 24, 2015

Conversation

weotch
Copy link
Contributor

@weotch weotch commented Jan 22, 2015

When applying a checked state to a checkbox, it is convenient to set the checked attribute with a boolean like the jQuery prop() API.

$bool = false; // Perhaps the property of a model
$el = Input::checkbox('foo', 'bar', ['checked' => $bool]);

#14 / #15 broke this by making NULL be the only wait to pass an attribute value that tells html-object not to add the attribute. This PR makes it so setting an attribute value to FALSE will NOT create the attribute. And setting it to TRUE will add the attribute as a property (no value).

@RTC1
Copy link

RTC1 commented Jan 24, 2015

Looks like this solves #20

Anahkiasen added a commit that referenced this pull request Jan 24, 2015
Treat attribtues set with boolean values as properties
@Anahkiasen Anahkiasen merged commit 5e640d1 into Anahkiasen:master Jan 24, 2015
@RTC1 RTC1 mentioned this pull request Mar 4, 2015
@biwerr
Copy link

biwerr commented Sep 5, 2016

Please don't treat the value attribute as property. This has some issues if you have checkbox values with true/false checkbox will not be send via form post if there is no value specified.

HtmlObject\Traits\Helpders@parseAttributes

// If set to boolean true, make the attribtue a property
            if ($value === true && $key!=='value') {
                $html[] = $key;
                continue;
            }

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.

None yet

4 participants