[MGNLUI-3445] RichTextField: Emptying the fields content and saving does not remove the property, just empties it -> required validation does not work Created: 27/May/15  Updated: 21/Aug/15  Resolved: 19/Aug/15

Status: Closed
Project: Magnolia UI
Component/s: dialogs, forms
Affects Version/s: 5.3.8
Fix Version/s: 5.3.11, 5.4.2

Type: Bug Priority: Major
Reporter: Christian Ringele Assignee: Evzen Fochr
Resolution: Fixed Votes: 0
Labels: ckeditor, support
Remaining Estimate: 0d
Time Spent: 1d 1h
Original Estimate: Not Specified

Issue Links:
causality
duplicate
is duplicated by MGNLUI-3446 RichTextField: required=true validato... Closed
relation
is related to MAGNOLIA-6345 Prevent null pointer exception in Lin... Closed
Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled
Date of First Response:
Sprint: Sprint 6 (Kromeriz)
Story Points: 3

 Description   

When removing the content of an existing RichTextField and saving, the property is not removed but just emptied.

This has as a consequence, that the "required=true" validator is not reacting, it accepts as the property exists.



 Comments   
Comment by Christian Ringele [ 28/May/15 ]

Update:
After testing the reason for the behavior is really that the property exists with an empty String.

First this is called to validate:

com.vaadin.ui.AbstractField.validate()

 if (isRequired() && isEmpty()) {
            throw new Validator.EmptyValueException(requiredError);
        }
        validate(getFieldValue());

isEmpty() calls com.vaadin.ui.AbstractField.getFieldValue()

if (dataSource == null || isBuffered() || isModified()) {
            return getInternalValue();
        }

        // There is no buffered value so use whatever the data model provides
        return convertFromModel(getDataSourceValue());
com.vaadin.ui.AbstractField.getFieldValue()

BUT dataSource is not NULL as the property exists.

So in the end its not Empty, and if you call getValue() in the field you get "" and not NULL.

Workaround:

  • Extend info.magnolia.ui.vaadin.richtext.MagnoliaRichTextField
    Override the method isEmpty() with the following code:
    @Override
        protected boolean isEmpty() {
            if(getValue() == ""){
                return true;
            }
            return super.isEmpty();
        }
    
  • Create a Extends of the info.magnolia.ui.form.field.factory.RichTextFieldFactory
    • allocate in there your Extended MagnoliaRichTextField
  • Add you custom Factory to this property: /modules/ui-framework/fieldTypes/textArea@factoryClass

Of course you cal also ass the code the the origin info.magnolia.ui.vaadin.richtext.MagnoliaRichTextField class and add it to the 'class' folder of your webapp (overload the class).

Comment by Evzen Fochr [ 19/Aug/15 ]

Set value to null is because we do not want to create (want to remove) jcr property with empty string value (same behavior as for normal textField).

Generated at Mon Feb 12 09:06:41 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.