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
JS validation: dynamically added form inputs are now validated #260
JS validation: dynamically added form inputs are now validated #260
Conversation
boris-brtan
commented
Jun 18, 2018
Q | A |
---|---|
Description, reason for the PR | problem with saving forms with dynamically added parameters |
New feature | No |
BC breaks | No |
Fixes issues | #190 |
Standards and tests pass | Yes |
Have you read and signed our License Agreement for contributions? | Yes |
c944a3a
to
3038ada
Compare
d04c194
to
26c595d
Compare
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.
Hi @boris-brtan, the review is done now, I have a few notes so please check them out. I really do not know what to do with the last commit so I asked @PetrHeinz for help.
CHANGELOG.md
Outdated
@@ -60,6 +60,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. | |||
- changed domain icon in e-shop domain administration can be saved | |||
- [#260 - Admin: Js validation: dynamically added parameters are now validated](https://github.com/shopsys/shopsys/pull/260) | |||
- validation is evaluated after dynamic parameters are added | |||
- jQuery migration console error logging is no more |
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.
I do not understand this commit at all, what was the problem?
@@ -4,7 +4,10 @@ | |||
Shopsys.validation = Shopsys.validation || {}; | |||
|
|||
Shopsys.validation.addNewItemToCollection = function (collectionSelector, itemIndex) { | |||
$($(collectionSelector)).jsFormValidator('addPrototype', itemIndex); | |||
$(collectionSelector).jsFormValidator('addPrototype', itemIndex); |
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.
why you changed the double cast?
}); | ||
|
||
function invalidateForm () { |
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.
this should rather be named to something like "disableJsFormValidation" as it disables JS validation on a form.
.toggle(); | ||
} | ||
|
||
Shopsys.validation.refreshBindings = function () { |
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.
We have Shopsys.register
component for that purpose - you can register a callback and that register newly added content on which the callback will be executed, see https://github.com/shopsys/shopsys/blob/master/packages/framework/src/Resources/scripts/common/register.js. I think this could serve for the purpose perfectly.
@@ -4,7 +4,10 @@ | |||
Shopsys.validation = Shopsys.validation || {}; | |||
|
|||
Shopsys.validation.addNewItemToCollection = function (collectionSelector, itemIndex) { | |||
$($(collectionSelector)).jsFormValidator('addPrototype', itemIndex); | |||
$(collectionSelector).jsFormValidator('addPrototype', itemIndex); | |||
if (Shopsys.validation.refreshBindings instanceof Function) { |
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.
is this necessary?
/** | ||
* @param int $productId | ||
*/ | ||
public function saveInvalidForm($productId) |
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.
I would name this method more specifically - it saves form with invalid parameter...
$productEditPage->saveInvalidForm(5); | ||
$productEditPage->assertSaveFormErrorBoxVisible(); | ||
|
||
$productEditPage->cleanUpWorkspaceAfterChanges(); |
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.
why? could not you just call $this->tester->acceptPopup()
?
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.
In this test the form is changed and browser will stop execution of next tests due to modal box that wants approval. Seems that opposite order of commands doesn't work if the test is ended and next test requests for different page modal box is not canceled.
LoginPage $loginPage, | ||
ProductEditPage $productEditPage | ||
) { | ||
$me->wantTo('not able to save invalid form'); |
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.
$me->wantTo('see that I am not able to save an invalid form');
?
public function saveInvalidForm($productId) | ||
{ | ||
$this->tester->amOnPage('/admin/product/edit/' . $productId); | ||
// scroll to have the button visible because of the fixed bars |
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.
is it necessary to scroll down? I thought that when you do just $this->tester->clickByCss('.js-parameters-item-add');
, it does not matter that the element is not in viewport, or does it?
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.
Yes, there is the problem with fixed elements with higher z-index. Click method will do the scroll to element like function
document.querySelector('.js-parameters-item-add').scrollIntoView()
and then client will try to click on it but there is element fixed bar above it and codeception will fail on error
Element \<a href="#" class="js-parameters-item-add btn btn--plus">...\</a>
is not clickable at point (338, 15).
Other element would receive the click: \<header class="web__header">...\</header>
CHANGELOG.md
Outdated
@@ -61,6 +61,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. | |||
- [#260 - Admin: Js validation: dynamically added parameters are now validated](https://github.com/shopsys/shopsys/pull/260) | |||
- validation is evaluated after dynamic parameters are added | |||
- jQuery migration console error logging is no more | |||
- support for multiple option of Flag and Brand items were added for form to be validated and not submitted if it is invalid |
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.
I honestly do not know what to do with this problem, the implementation in JsFormValidatorFactory::normalizeViewTransformers()
is (already was) really confusing and fragile 😞 It should probably be refactored completely but I do not know how... @PetrHeinz could you please help us here? 👼
While testing, I noticed yet another bug but it seems that it is already on master so I created a separate issue - #268 |
7db2a8d
to
8e2e30f
Compare
After discussion with @boris-brtan we've reduced scope of this PR as there are two unrelated issues atm:
Can someone please do a code review of this fix with the reduced scope? |
8e2e30f
to
6b718b4
Compare
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.
Hi guys, I reviewed and tested the changes and everything now seems ok, you can pass the task to business validation 👍
CHANGELOG.md
Outdated
@@ -78,6 +78,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. | |||
- [#352 - flushes executed in loops are now executed outside of loop](https://github.com/shopsys/shopsys/pull/352) | |||
- [#342 - procedures are now executed only if relevant columns are changed](https://github.com/shopsys/shopsys/pull/342) | |||
- [#362 - guidelines-for-pull-request.md: fixed indentation of lines and code blocks](https://github.com/shopsys/shopsys/pull/362) | |||
- [#260 - JS validation: dynamically added form inputs are now validated](https://github.com/shopsys/shopsys/pull/260) |
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.
Please correct changelog entry because new version was released.
- Shopsys.validation modified so it applies handlers for newly registered content - code was made more consistent across usages
- avoids issues during parsing, including problems with parsing whitespace characters
6b718b4
to
569002f
Compare