-
Notifications
You must be signed in to change notification settings - Fork 119
Conversation
Sometimes, we required from our form a conditional behaviour, like: $builder->text('email')->disabled(($profile->isAdmin()) ? true : false);
I would realy like to see this merged! |
@daguilarm Can you add tests for this? Will merge when there's tests, thanks 👍 |
I'm proposing a similar solution in #110, though I think a bit more flexible as it's a magic method implementation. Thoughts? |
I want this so bad.....
|
Thanks for adding the tests! What do we think the expected behavior should be if someone did something like:
Right now, it looks like this field would still be required. What do you think? @jesseleite I think I'm going to add the behavior from this PR even if we do add the magic method style you suggested in your PR, but we can consider the changes you've proposed separately. My instinct is that I don't love stuff that magically looks for substrings in method names (even bugs me when Laravel does it) but can still definitely discuss it. |
something like this? |
I think maybe something like this: public function required($conditional = true)
{
$this->setBooleanAttribute('required', $conditional);
return $this;
}
protected function setBooleanAttribute($attribute, $value)
{
if ($value) {
$this->setAttribute($attribute, $attribute);
} else {
$this->removeAttribute($attribute);
}
} It's totally fine to call |
Perfect!! |
Thank you all! I really missed this and i use this package a lot!! |
@adamwathan I love the magic method implementation in #110. I understand what you mean on the substring Form::text('test')->wathan('sexy');
// <input type="text" name="test" wathan="sexy">
Form::text('test')->wathanIf(false, 'ugly');
// <input type="text" name="test"> This PR hardcodes the 'conditionalable' (oh geez) expression to attributes like ...That said, if you want to close my other PR, I won't be sad :) |
Sometimes, we required from our form a conditional behaviour, like:
$builder->text('email')->disabled(($profile->isAdmin()) ? true : false);