Results 1 to 4 of 4

Thread: Binding doesn't work with validation

  1. #1
    Sencha Premium Member yorl1n's Avatar
    Join Date
    Mar 2015
    Location
    Germany
    Posts
    294
    Answers
    30

    Default Binding doesn't work with validation

    Hello everyone,


    Here is a Fiddle with the problem. The first field has validations:
    Code:
    allowBlank: false,
    maxLength: 5

    So as long as you type a value into the first field the binding works until the validation fails - > 5 symbols. The same for first field when you remove a value. For the second field there is no problem with binding while it has no validation.
    The question is how to avoid this annoying behavior and force bind to work for "invalid" fields?
    Thanks in advance

  2. #2
    Sencha User joel.watson's Avatar
    Join Date
    Nov 2014
    Posts
    3,120
    Answers
    446

    Default

    Hi--

    This is by design to avoid updating bindings with invalid values.

    I know there are a few overrides which community members have implemented, if you're interested in testing them out. For example: http://extjs.eu/ext-examples/#grid-and-form

    Thanks!
    Joel

  3. #3
    Sencha Premium Member yorl1n's Avatar
    Join Date
    Mar 2015
    Location
    Germany
    Posts
    294
    Answers
    30

    Default

    Thanks joel.watson for reply,
    I have seen this solution, but I didn't find a point of the trick(what was exactly overridden to make bind to work). In this example Model is used, but I don't need a Model, but a plain UI component such as Textfield with its integrated validation(allowBlank or maxLength).
    If there is no simple solution, I will spend hours to find it instead of implementation of our project.
    From my point of view this should work out of the box (at least there should be a trigger to turn on/off binding on validation). Moreover I think there are cases when the binding should work only when the value is invalid.
    So I propose to add some property with values 'valid', 'invalid', 'both' to make binding work in cases when values are only valid, only invalid or always respectively (valid by default).
    Thanks.

  4. #4
    Sencha Premium Member yorl1n's Avatar
    Join Date
    Mar 2015
    Location
    Germany
    Posts
    294
    Answers
    30

    Default

    So I have overridden a publishValue method of Ext.form.field.Base to avoid this behavior.

    Code:
    Ext.override(Ext.form.field.Base, {
                publishValue: function () {
                    var me = this;
    
    
                    if (me.rendered) {
                        switch (me.bindOn) {
                            case 'both':
                                me.publishState('value', me.getValue());
                                break;
                            case 'invalid':
                                if (me.getErrors().length) {
                                    me.publishState('value', me.getValue());
                                }
                                break;
                            default:
                                if (!me.getErrors().length) {
                                    me.publishState('value', me.getValue());
                                }
                        }
                    }
                }
            });
    Marking a field with bindOn ('valid', 'invalid', 'both') does the stuff.
    I hope it will be helpful for someone.

Similar Threads

  1. Replies: 3
    Last Post: 12 Aug 2015, 7:25 PM
  2. The listpaging event binding add button doesn't work
    By brucema in forum Sencha Architect 2.x: Bugs
    Replies: 0
    Last Post: 9 Sep 2012, 7:03 AM
  3. Replies: 2
    Last Post: 12 Dec 2011, 4:22 PM
  4. Combobox binding doesn't work
    By pejo in forum Ext GWT: Discussion
    Replies: 6
    Last Post: 22 Nov 2010, 7:42 AM
  5. Replies: 9
    Last Post: 23 Dec 2008, 7:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •