-
-
Notifications
You must be signed in to change notification settings - Fork 147
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
Inconsistent return type of getLabel
#241
Comments
Awesome! Thanks a lot. How about |
I think it is correct "covariant type":https://en.wikipedia.org/wiki/Covariance_and_contravariance_(computer_science)#Covariant_method_return_type. |
Any return type is covariant to "not specified". 🤷♂️ Anyway, it limits extensibility and breaks consistency. BUT hey, we are at least able to return any string (including empty strings) wrapped inside |
It is specified forms/src/Forms/Controls/BaseControl.php Line 269 in fdedfc2
|
Version: 3.*
Problem description
For some reason,
CheckBox
,HiddenField
andButton
have no label by default. But the other inputs do have labels.What If we did want our checkboxes to actually have a label? And render it like a label of the other elements? (For design consistency or any other reason.)
Or we wanted to make it Bootstrap-compatible (render the input outside of
<label>
tag)?If anyone could make Nette forms use their own implementation of Checkbox ... but we can't, since in order to use
addCheckbox
method we need to return an instance ofNette\Forms\Control\Checkbox
and since itsgetLabel
method is defined aspublic function getLabel($caption = null): void
there is no way to force any other return type on it...Possible solution
void
return type onCheckbox::getLabel
method.In Nette 2.4 we have solved this elegantly this way (one is able to chose from 3 different styles of how
getControl
andgetLabel
return their values):I'm open to providing a PR for the above code.
Please also consider dropping the return type of the other methods, for consistency sake, even though it makes less sense to override labels of these methods:
RadioList::getLabel
HiddenField::getLabel
Button::getLabel
The text was updated successfully, but these errors were encountered: