Skip to content

Commit

Permalink
IBX-9097: [PB] Error with Richtext validator in nested_attribute (#1371)
Browse files Browse the repository at this point in the history
  • Loading branch information
GrabowskiM authored Oct 24, 2024
1 parent cd4176a commit 2867274
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { getTranslator } from '../../helpers/context.helper';

const { ibexa } = window;

class RichTextValidator extends ibexa.BaseFieldValidator {
Expand All @@ -18,15 +20,24 @@ class RichTextValidator extends ibexa.BaseFieldValidator {
* @memberof RichTextValidator
*/
validateInput(event) {
const Translator = getTranslator();
const fieldContainer = event.currentTarget.closest(this.selectorField);
const isRequired = fieldContainer.classList.contains('ibexa-field-edit--required');
const label = fieldContainer.querySelector(this.labelSelector).innerHTML;
const label = fieldContainer.querySelector(this.labelSelector)?.innerHTML;
const isEmpty = !this.richtextEditor.getData().length;
const isError = isRequired && isEmpty;
const result = { isError };

if (isError) {
result.errorMessage = ibexa.errors.emptyField.replace('{fieldName}', label);
if (label) {
result.errorMessage = ibexa.errors.emptyField.replace('{fieldName}', label);
} else {
result.errorMessage = Translator.trans(
/*@Desc("This value should not be blank.")*/ 'error.required.field_not_blank',
{},
'forms',
);
}
}

return result;
Expand Down

0 comments on commit 2867274

Please sign in to comment.