-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Allow jquery optional. #20582
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
base: 22.0
Are you sure you want to change the base?
Allow jquery optional. #20582
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces the ability to make jQuery optional in Yii2 while maintaining backward compatibility. The implementation adds a useJquery
configuration property to applications and refactors widgets and validators to use client script interfaces, allowing for jQuery-free implementations.
Key changes:
- Added
useJquery
property to web and console applications - Created client script interfaces for modular validation and widget functionality
- Implemented jQuery-specific client scripts as separate classes
- Moved jQuery-dependent test code to dedicated test files
Reviewed Changes
Copilot reviewed 71 out of 71 changed files in this pull request and generated 4 comments.
Show a summary per file
File | Description |
---|---|
framework/web/Application.php |
Added useJquery property with default true |
framework/console/Application.php |
Added useJquery property with default false |
framework/widgets/ActiveForm.php |
Added client script interface support |
framework/validators/Validator.php |
Added formatted client message method |
Multiple validator files | Refactored to use client script interfaces |
jQuery client script classes | New jQuery-specific implementations |
Test files | Reorganized tests and added jQuery-specific test coverage |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
framework/jquery/validators/StringValidatorJqueryClientScript.php
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 71 out of 71 changed files in this pull request and generated 2 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
…`, `GridView`, and `ActiveForm`/`ActiveField`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 71 out of 71 changed files in this pull request and generated 1 comment.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
* | ||
* @since 2.2.0 | ||
*/ | ||
public bool $useJquery = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the use for it in console application?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because you can use the validators in the console, and JS code will be generated, as in the issue described (#8452), by setting it to false
by default, no assets will be registered and no JS code will be generated.
This solution implements a way to make jQuery optional, while trying to keep BC as low as possible:
useJquery
property is added toyii\console\Application
andyii\web\Application
this allows you to control whether jQuery is used or not.Two interfaces have been added to add the clientScript to validators, widgets, components, etc.
Fixed generation of labels, whether custom or not, when enclosedByLabel ===
false
, for bothcheckbox()
andradio()
.checkbox
/radio
label rendering whenenclosedByLabel
isfalse
and raise code coverage100%
inActiveField::class
. #20573To install the assets, i added
php-forge/foxy
, which i maintain and allows you to install assets easily using thecomposer
installer. i think it would be great to use CDN to manage the assets, so we don't depend on anything external.Issues related: