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

IBX-2360: Validation content type create/edit #334

Merged
merged 5 commits into from
Feb 28, 2022

Conversation

lucasOsti
Copy link
Contributor

@lucasOsti lucasOsti commented Feb 21, 2022

Question Answer
Tickets https://issues.ibexa.co/browse/IBX-2360
Bug fix? yes
New feature? no
BC breaks? no
Tests pass? yes
Doc needed? no
License GPL-2.0

Added form validation by javascript

Checklist:

  • Coding standards ($ composer fix-cs)
  • Ready for Code Review

@lucasOsti lucasOsti marked this pull request as draft February 21, 2022 10:14
@lucasOsti lucasOsti changed the title [WIP]Validation content type IBX-2360: Validation content type create/edit Feb 21, 2022
@lucasOsti lucasOsti marked this pull request as ready for review February 21, 2022 14:10
@lucasOsti lucasOsti added Bug Something isn't working Ready for review labels Feb 21, 2022
@@ -253,7 +260,60 @@
})
.catch(ibexa.helpers.notification.showErrorNotification);
};
const validateInput = (input) => {
const isInputValid = !!input.value;
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe it would be better with sth like is Input not empty? as non empty input isn't necessary valid, I think

}
};
const validateForm = () => {
const inputsToValidate = editForm.querySelectorAll('.ibexa-input[required]:not([disabled]):not([hidden])');
Copy link
Contributor

Choose a reason for hiding this comment

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

what would you say on adding this selecto to some const? you use it few times here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not a big fan of this type of variables but ok :)

validateInput(input);
});

for (const [fieldDefinitionIdentifier, inputsStatus] of Object.entries(fieldDefinitionsStatuses)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why not forEach loop?

Comment on lines 314 to 316
input.addEventListener('change', () => validateForm(input), false);
input.addEventListener('blur', () => validateForm(input), false);
input.addEventListener('input', () => validateForm(input), false);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
input.addEventListener('change', () => validateForm(input), false);
input.addEventListener('blur', () => validateForm(input), false);
input.addEventListener('input', () => validateForm(input), false);
input.addEventListener('change', validateForm, false);
input.addEventListener('blur', validateForm, false);
input.addEventListener('input', validateForm, false);

Copy link
Contributor

Choose a reason for hiding this comment

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

And AFAICS validateForm does not take any parameter, so actually no need to pass input.

@@ -80,7 +89,9 @@

const fieldGroupInput = fieldNode.querySelector('.ibexa-input--field-group');
const removeFieldsBtn = fieldNode.querySelectorAll('.ibexa-collapse__extra-action-button--remove-field-definitions');
const inputsToValidate = fieldNode.querySelectorAll(SELECTOR_INPUTS_TO_VALIDATE);
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess we don't have sonar/eslint checks in this repo yet, but it seems that it overrides the variable from the upper scope?

Comment on lines 279 to 280
if (isEditFormValid && isInputEmpty) {
isEditFormValid = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that checking whether isEditFormValid is true is not needed. You are also checking isInputEmpty in validateForm - can we avoid checking it twice?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

solved in private conversation

Comment on lines +441 to +442
if (!fieldDefinitionsCount) {
isEditFormValid = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

My guess is you put this check here instead of validateForm, because you wanted to display a noFieldsAddedError message, but for me, it is not intuitive to have this checkout outside validateForm.
Can it be put there maybe? Or maybe it is intuitive for you? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

solved in private conversation


isEditFormValid = true;

inputsToValidate.forEach((input) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: could this be iterated field definition by field definition without fieldDefinitionsStatuses?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

solved in private conversation

@dew326 dew326 merged commit 412a9af into ibexa:main Feb 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working QA approved
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants