fix: take maxlength from $maxLength instead of $cols - #130
Merged
Conversation
addText() rendered maxlength="$cols" whenever $maxLength was passed, so the maximum length of the value was decided by the visual width of the input and $maxLength itself never reached the HTML. addPassword() delegates to addText() and inherited the same bug. The control now gets $maxLength through the TextInput constructor, which is how nette/forms itself applies it, and $cols keeps setting the cols attribute on its own. addEmail() dropped its $maxLength too — it called addText() with the label only — so its documented default of 255 was never applied. It now passes the value through, matching Nette\Forms\Container::addEmail(). The "ignored" @PARAM notes on addText()/addTextArea() described neither the old nor the new behaviour and are replaced with what the arguments actually do. Closes #104 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #130 +/- ##
============================================
+ Coverage 97.05% 97.25% +0.19%
+ Complexity 309 308 -1
============================================
Files 25 25
Lines 986 984 -2
============================================
Hits 957 957
+ Misses 29 27 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #104.
The bug
BootstrapContainerTrait::addText()guarded on$maxLengthbut then wrote$colsinto the attribute:So
addText('name', 'Name', 10, 50)renderedmaxlength="10"— the maximum length of the value was decided by the visual width of the input, and the$maxLengththat was actually asked for never reached the HTML. Passing$maxLengthwithout$colsrenderedmaxlength="".addPassword()delegates toaddText(), so it carried the same bug.The fix
$maxLengthnow goes through theTextInputconstructor, which is howNette\Forms\Container::addText()applies it, and$colskeeps setting thecolsattribute on its own.Also in here
addEmail()never applied its$maxLength. It takesint $maxLength = 255and then calledaddText($name, $label)with the label only, so the argument was silently dropped — same defect, same two lines of code. It now passes the value on.This one is a visible output change: every field built with
addEmail()starts renderingmaxlength="255"(or whatever was passed) where it previously rendered nomaxlengthat all. That is whatNette\Forms\Container::addEmail()has always produced, and the alternative is leaving a documented parameter that does nothing — flagging it since it lands in rendered HTML for existing users, and this branch is aimed at the next major anyway.The
@param int|null $cols ignored/$maxLength ignorednotes onaddText()andaddTextArea()described neither the old nor the new behaviour — both arguments have always been written to attributes — so they now say what the arguments do.Not changed:
addText()renders$colsas acolsattribute, while Nette renders it assize(colsis a<textarea>attribute, not an<input>one). That is a separate pre-existing divergence, it is not what #104 reports, and correcting it would silently rewrite the HTML of every field that passes$cols— worth its own issue if you want it aligned.Tests
Five tests in
tests/Traits/BootstrapContainerTraitTest.phpcoveringmaxlengthfrom$maxLengthalongsidecols,$maxLengthwithout$cols,$colsalone rendering nomaxlength,addPassword()passing it through, andaddEmail()applying both its default and an explicit value. Four of the five fail on master.make tests(163 tests, 250 assertions),make phpstanandmake csall pass. No rendering fixture undertests/data/changed — none of them build an email field.🤖 Generated with Claude Code