Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

  • Isomorphic
    replied
    The former.

    Leave a comment:


  • brandontrogers
    replied
    So is the fix for the validator to run at least once given any array or to set the value of the MultiComboBoxItem back to null when all elements are removed?

    Leave a comment:


  • Isomorphic
    replied
    We assume you noticed that your validator is called for each selection in this multi-select item, since you're ignoring the passed value and checking item.getValues() instead.

    After a selection is made and then removed, the item's value is [], rather than null - since the validator runs for each item in the array, and since it was emtpy, the validator didn't run.

    We've added a fix for builds dated August 11 and later.
    Last edited by Isomorphic; 10th Aug 2019, 12:26.

    Leave a comment:


  • brandontrogers
    replied
    Code:
    VLayout layout = new VLayout();
            final DynamicForm form = new DynamicForm();
            final MultiComboBoxItem item = new MultiComboBoxItem("MultiComboBox");
            IButton button = new IButton("Validate");
    
            item.setValueMap(new HashMap() {{ put(1, "First Option"); put(2, "Second Option"); }});
            item.setValidators(new CustomValidator() {
    
                @Override
                protected boolean condition(Object value) {
                    if (item.getValues() != null && item.getValues().length > 0) {
                        SC.logWarn("Valid");
                        return true;
                    } else {
                        SC.logWarn("Not Valid");
                        return false;
                    }
                }
            });
            form.setFields(item);
            button.addClickHandler(new ClickHandler() {
    
                @Override
                public void onClick(ClickEvent event) {
                    form.validate();
                }
            });
            layout.setMembers(form, button);
            layout.draw();
    Clicking validate upon initial draw logs "Not Valid", adding First Option and clicking logs "Valid", removing First Option and clicking logs nothing.

    Leave a comment:


  • Isomorphic
    replied
    That's very surprising, as the validation system is completely independent of the specific FormItem involved in editing values.

    Could you please show complete code that reproduces this problem?

    Leave a comment:


  • brandontrogers
    replied
    I've removed the setRequired(true) and tried just using a CustomValidator with the setValidators(...) API and the CustomValidator does not fire at all if a value has been selected and then removed.

    final MultiComboBoxItem item = new MultiComboBoxItem();
    item.setValidators(new CustomValidator() {

    @Override
    protected boolean condition(Object value) {
    // this never fires
    if (item.getValues() != null && item.getValues().length > 0) {
    return true;
    }
    return false;
    }
    });

    Leave a comment:


  • Isomorphic
    replied
    A required validator requires a non-null value, and an empty array is non-null, and an empty array is also the correct and expected value for a multiple:true field that has had a value but has been cleared out. Basically there's a distinction between an empty set and null - they are not the same.

    If an empty set is not a valid value here, you should add a validator that checks for that. Or you could add logic that forces empty sets to null if that's never a valid value in your application.

    Leave a comment:


  • MultiComboBoxItem required validator not firing when an item is added and then removed

    When using a MultiComboBoxItem that we have set a value map that also is setRequred(true) validators do not fire if the user has selected a value from the MultiComboBoxItem and then removed it (clicked the x). A getValues() call seems to be returning an empty String array. I tried implementing a CustomValidator on the MultiComboBoxItem to see if it ever fires and this does not fire as well. It seems to be bypassing all validation on form.validate() even though other FormItems on the form validate correctly.

    version: v11.1p_2019-05-04/Enterprise Deployment (built 2019-05-04)
Working...
X