Skip to content
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

Fix #8452 Jquery Extraction (attempt 2) #14865

Merged
merged 15 commits into from
Dec 30, 2017

Conversation

klimov-paul
Copy link
Member

Q A
Is bugfix? no
New feature? yes
Breaks BC? yes
Tests pass? yes
Fixed issues #12588, preparing for #8452

Migrated from #13839

@klimov-paul klimov-paul added severity:BC breaking Either breaks backwards compatibility or fixed previously made breakage type:enhancement labels Sep 21, 2017
@klimov-paul klimov-paul added this to the 2.1.0 milestone Sep 21, 2017
@schmunk42
Copy link
Contributor

Looks neat.

Is this planned as a first step to keep the whole system intact, but should yii\jquery be moved to https://github.com/yiisoft/yii2-jquery in a next step?

@samdark
Copy link
Member

samdark commented Sep 22, 2017

@schmunk42 yes, that's the plan.

/**
* @inheritdoc
*/
public $clientValidatorMap = [
Copy link
Member

Choose a reason for hiding this comment

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

I suggest to move this array to a separate method getClientValidatorMap() to make it easier to add custom validators to this map, or override existing.

Copy link
Member

Choose a reason for hiding this comment

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

Or, maybe, create a ClientValidatorFactory and inject it in ActiveFormClientScript.
It will be responsible for creating ClientValidator based on Validator, than it should be easier to add new mappings

Copy link
Member Author

Choose a reason for hiding this comment

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

defaultClientValidatorMap() added

* ```php
* <?php $form = \yii\widgets\ActiveForm::begin([
* 'id' => 'example-form',
* 'as clientScript' => \yii\jquery\ActiveFormClientScript::class,
Copy link
Member

@samdark samdark Dec 15, 2017

Choose a reason for hiding this comment

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

What are pros compared to extending ActiveFormClientScript from ActiveForm instead of making it a behavior?

Copy link
Member

Choose a reason for hiding this comment

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

OK. That was 1st approach. Cons are described here: #13839 That's why behaviors.

@@ -8,7 +8,7 @@
namespace yii\captcha;
Copy link
Member

@samdark samdark Dec 15, 2017

Choose a reason for hiding this comment

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

Captcha should be moved to separate repository. Script should be adjusted not to use jQuery.

Could be done in separate pull request after this one is merged.

/**
* @inheritdoc
*/
public function build($validator, $model, $attribute, $view)
Copy link
Member

@samdark samdark Dec 16, 2017

Choose a reason for hiding this comment

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

It could not be built with any other validator than BooleanValidator from core framework so it makes sense to type-hint here and in similar cases.

@samdark
Copy link
Member

samdark commented Dec 16, 2017

The pull request is big so I did a drawing while reviewing:

yii21_clientscript

  1. GridView at core side is stripped down. GridViewCleintScript at jQuery extension side is a behavior that now contains all the stripped clientside-specific code.
  2. Validator classes at jQuery extension side are mapped to core validators via ActiveFormClientScript behavior for ActiveForm (similar to point 1). Each validator at jQuery extension is a class that, accepting a corresponding validator instance from the core, builds JavaScript necessary for client validation.
  3. Captcha is going to be extracted into its own extension. There isn't much jQuery so it can be rewritten using pure JavaScript so there are no jQuery dependency when it is required in a project.

Overall, approach makes perfect sense.

Sorry that it took that long to review it properly.

@samdark
Copy link
Member

samdark commented Dec 29, 2017

@klimov-paul, it is possible to resolve conflicts? Other than that, the approach is good as well as code itself. The only minor thing to consider is #14865 (comment). Ready to merge when conflicts will be resolved. If you're busy, I can allocate time for it and do it myself, just tell me.

@klimov-paul
Copy link
Member Author

Conflicts resolved.

@samdark samdark merged commit bf116e6 into yiisoft:2.1 Dec 30, 2017
@samdark
Copy link
Member

samdark commented Dec 30, 2017

Merged. That was big one. Thank you for taking care of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
severity:BC breaking Either breaks backwards compatibility or fixed previously made breakage type:enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants