Skip to content

Comments

Fix url form field#1439

Merged
LukeTowers merged 7 commits intodevelopfrom
fix-url-field
Feb 20, 2026
Merged

Fix url form field#1439
LukeTowers merged 7 commits intodevelopfrom
fix-url-field

Conversation

@mjauvin
Copy link
Member

@mjauvin mjauvin commented Jan 14, 2026

FormField now accepts new attributes dynamically.

Summary by CodeRabbit

  • Improvements

    • Textarea and widget fields now default to a larger, more usable size.
    • URL inputs better respect maxlength, minlength, pattern, placeholder and size attributes for improved validation and UX.
    • Telephone field placeholders are now localized.
  • Bug Fixes

    • More consistent attribute rendering, improving autocomplete and overall form behavior.

@mjauvin mjauvin added this to the 1.2.10 milestone Jan 14, 2026
@mjauvin mjauvin requested a review from LukeTowers January 14, 2026 20:27
@mjauvin mjauvin self-assigned this Jan 14, 2026
@mjauvin mjauvin added the maintenance PRs that fix bugs, are translation changes or make only minor changes label Jan 14, 2026
@coderabbitai
Copy link

coderabbitai bot commented Jan 14, 2026

Walkthrough

Removed default value for FormField::$size, added magic getters (__get, __isset) to expose config-backed properties, auto-sets size to 'large' for textarea/widget in displayAs, and reworked which config keys are applied. URL field partial inlines guarded attribute emission; tel field placeholder now wrapped with translation.

Changes

Cohort / File(s) Summary
FormField class
modules/backend/classes/FormField.php
Removed default 'large' from public $size (now uninitialized); docblock updated to `string
Form URL field partial
modules/backend/widgets/form/partials/_field_url.php
Moved conditional emission of autocomplete, maxlength, minlength, pattern, placeholder, and numeric size into the opening <input> tag with guarded inline expressions; removed the separate secondary attribute block that previously emitted several attributes.
Form tel field partial
modules/backend/widgets/form/partials/_field_tel.php
Wrapped placeholder output with translation: uses e(trans($field->placeholder)) instead of raw e($field->placeholder).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Add tel form field #1440 — touches the same tel form field partial (modules/backend/widgets/form/partials/_field_tel.php) and may overlap with placeholder/attribute rendering changes.
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Title check ⚠️ Warning The PR title 'Fix url form field' is only partially related to the changeset. While one modified file is _field_url.php, the primary changes extend far beyond just fixing the URL field—they fundamentally refactor the FormField class with new magic methods, alter property initialization, and modify multiple field templates. Consider a more comprehensive title like 'Refactor FormField with dynamic attribute support and magic methods' or 'Add magic methods to FormField and refactor field templates' to better reflect the scope of changes.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-url-field

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot]

This comment was marked as resolved.

@LukeTowers LukeTowers modified the milestones: 1.2.10, 1.2.11 Feb 4, 2026
@LukeTowers LukeTowers modified the milestones: 1.2.11, 1.2.12 Feb 18, 2026
@LukeTowers LukeTowers merged commit 4a51b19 into develop Feb 20, 2026
13 of 14 checks passed
@LukeTowers LukeTowers deleted the fix-url-field branch February 20, 2026 09:00
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@modules/backend/classes/FormField.php`:
- Around line 94-96: The textarea template `_field_textarea.php` unsafely emits
"size-<?= $field->size ?>" when the FormField::$size property can be null;
update the class attribute in `_field_textarea.php` to only append the size
class when $field->size is set (e.g., use isset($field->size) to conditionally
add 'size-' . e($field->size) or an empty string), mirroring the null-safe
pattern used in `_field_url.php` and `_field_tel.php`; keep the rest of the
markup unchanged and continue to rely on displayAs() defaulting textarea size to
'large' when appropriate.

Comment on lines +94 to +96
* @var string|int Specifies a size. Possible values for textarea: tiny, small, large, huge, giant.
*/
public $size = 'large';
public $size;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Find all usages of $field->size in form partials and related template files

echo "=== Searching for \$field->size usages ==="
rg -n '\$field->size' --glob '*.php' modules/backend/widgets/form/

echo ""
echo "=== Searching for direct size comparisons/operations ==="
rg -n '->size\s*[!=<>]' --glob '*.php' modules/backend/widgets/form/

echo ""
echo "=== Checking is_numeric guards and other null checks ==="
rg -n 'is_numeric.*size|size.*is_numeric' --glob '*.php' modules/backend/widgets/form/

Repository: wintercms/winter

Length of output: 1420


🏁 Script executed:

cat -n modules/backend/widgets/form/partials/_field_textarea.php | head -20

Repository: wintercms/winter

Length of output: 610


🏁 Script executed:

# Check FormField constructor to see if $size is initialized
sed -n '1,150p' modules/backend/classes/FormField.php | grep -A 30 'public function __construct'

Repository: wintercms/winter

Length of output: 42


🏁 Script executed:

# Search for the constructor in FormField
rg -n 'function __construct' modules/backend/classes/FormField.php -A 20

Repository: wintercms/winter

Length of output: 617


🏁 Script executed:

# Check displayAs() method to see when it sets $size = 'large'
rg -n 'public function displayAs' modules/backend/classes/FormField.php -A 80 | head -100

Repository: wintercms/winter

Length of output: 2632


Fix null-safety issue in _field_textarea.php template.

The $size property no longer has a default value, and while displayAs() auto-sets 'large' for textarea types, the _field_textarea.php template unsafely outputs size-<?= $field->size ?> without checking for null. This produces an invalid CSS class name size- when $size is null.

Update _field_textarea.php line 9 to guard against null, similar to how _field_url.php and _field_tel.php handle it:

Suggested fix
class="form-control field-textarea <?= isset($field->size) ? 'size-' . e($field->size) : '' ?>"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@modules/backend/classes/FormField.php` around lines 94 - 96, The textarea
template `_field_textarea.php` unsafely emits "size-<?= $field->size ?>" when
the FormField::$size property can be null; update the class attribute in
`_field_textarea.php` to only append the size class when $field->size is set
(e.g., use isset($field->size) to conditionally add 'size-' . e($field->size) or
an empty string), mirroring the null-safe pattern used in `_field_url.php` and
`_field_tel.php`; keep the rest of the markup unchanged and continue to rely on
displayAs() defaulting textarea size to 'large' when appropriate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance PRs that fix bugs, are translation changes or make only minor changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants