Results 1 to 10 of 10

Thread: Dynamically change regex

  1. #1
    Sencha Premium Member
    Join Date
    Oct 2015
    Posts
    138
    Answers
    3

    Default Dynamically change regex

    Is there a possibility to dynamically enable/disable or change the value of a regex property?

  2. #2
    Sencha Premium Member
    Join Date
    Oct 2015
    Posts
    138
    Answers
    3

    Default

    Any opinion?

  3. #3
    Sencha Premium Member
    Join Date
    Oct 2015
    Posts
    138
    Answers
    3

    Default

    I can set a form's field to disable:

    Code:
    TargetField.disabled = true;
    but I tried to set the validation manually, for example:

    Code:
    TargetField.setConfig('validateOnChange', true);
    or

    Code:
    TargetField.setValidation(true);
    but it has no effect.

    Basically this field needs NOT be submitted anymore (that's why I am disabling it), and as such I need to bypass the validation. At the moment, it's not causing problem with submission when failing the validation (pretty much because it is NOT submitted). But I want to get rid of the red highlight because the user thinks there's going to be something wrong with the submission.

    What is the correct way to make this field NOT be highlighted red even if it fails validation?

  4. #4
    Sencha Premium User
    Join Date
    Nov 2013
    Posts
    320
    Answers
    9

    Default

    You can try invalidCls:'' as per https://fiddle.sencha.com/#fiddle/16ql

  5. #5
    Sencha Premium Member
    Join Date
    Oct 2015
    Posts
    138
    Answers
    3

    Default

    Quote Originally Posted by alexander.urban View Post
    You can try invalidCls:'' as per https://fiddle.sencha.com/#fiddle/16ql
    Did not seem to have any effect... I am not getting any error, and from the console log I can see invalidCls is set, but it doesn't make a difference.

  6. #6
    Sencha Premium Member
    Join Date
    Oct 2015
    Posts
    138
    Answers
    3

    Default

    Any other suggestion? I am quite sure there is a way for this... better if someone can find the solution within ExtJS rather than CSS, but anything that works would do...

  7. #7
    Sencha Premium Member
    Join Date
    Apr 2015
    Posts
    122
    Answers
    10

    Default

    I don't know if I have understood correctly but you want the field not be validated because is not going to be submitted?

    If so you can set
    validateOnChange : false,
    validateOnBlur : false,
    on that field.

    I don't know if that is enough but for the fiddle it was, try it:

    Code:
    Ext.application({    name : 'Fiddle',
    
    
        launch : function() {
            Ext.create('Ext.form.Panel',{
                items:[{
                    fieldLabel:'Invalid red',
                    xtype:'textfield',
                    vtype:'email'
                },{
                    fieldLabel:'Invalid normal',
                    xtype:'textfield',
                    vtype:'email',
                    validateOnChange : false,
                    validateOnBlur : false,
                    listeners : {
                        validitychange : function(f){
                            debugger; //should not come here
                        }
                    }
                }],
                renderTo:Ext.getBody()
            })
        }
    });

    I hope it helps

  8. #8
    Sencha Premium Member
    Join Date
    Apr 2015
    Posts
    122
    Answers
    10

    Default

    Re-reading you want to disable the validation if something happens in your app right? so not from the beginning.
    The button will disable the validations in this case:

    Code:
    Ext.application({    name : 'Fiddle',
    
    
        launch : function() {
            Ext.create('Ext.form.Panel',{
                items:[{
                    fieldLabel:'Invalid red',
                    xtype:'textfield',
                    vtype:'email'
                },{
                    fieldLabel:'Invalid normal',
                    xtype:'textfield',
                    itemId : 'my-email',
                    vtype:'email',
                    listeners : {
                        validitychange : function(f){
                            debugger;
                        }
                    }
                }],
                renderTo:Ext.getBody(),
                buttons : [{
                    text : 'disable invalid normal',
                    handler : function(){
                        var email = this.up('form').down('#my-email');
                        email.validateOnChange = false;
                        email.validateOnBlur = false;
                    }
                }]
            })
        }
    });

  9. #9
    Sencha Premium Member
    Join Date
    Oct 2015
    Posts
    138
    Answers
    3

    Default

    It's still not working... maybe there's an error in the way I reference the field?

    The form field has a reference defined, let's call it 'fixedfieldref'. So for example I can easily disable the field with the following:

    Code:
    editor.lookupReference( 'fixedfieldref' ).disabled = true;
    The reason why I am doing this, is that some fields in our form can be defined ONLY when the item is created and the form is filled the first time. Later the user can re-open an editor to change SOME fields in the form, but not others. This field with reference: 'fixedfieldref' is one of those.

    So when creating a new item in the store, a form editor opens and the user can (actually HAS, and these fields are set to allowBlank: false) set these fields. But if later the user wants to change something in the form, the previous line of code makes sure that such fields cannot be changed anymore.

    The problem is that those fields have regex validators defined. These are supposed to be bypassed when store entries are not created by the user, but are externally created, in which case more characters are allowed. When re-opening the form for editing, such extra characters would fail the original regex and make the field show up RED -> this is what I want to get rid of!

    However none of the following lines seem to have any effect:

    Code:
    editor.lookupReference( 'idfield' ).validation = true;
    editor.lookupReference( 'idfield' ).setValidation(true);
    editor.lookupReference( 'idfield' ).validateOnChange = false;
    editor.lookupReference( 'idfield' ).validateOnBlur = false;
    editor.lookupReference( 'idfield' ).setConfig('validateOnChange', false);
    editor.lookupReference( 'idfield' ).setConfig('validateOnBlur', false);
    No error is shown on the console log when using those lines, but the field is still RED.

  10. #10
    Sencha Premium Member
    Join Date
    Apr 2015
    Posts
    122
    Answers
    10

    Default

    If you cannot dynamically change these properties maybe it is better that you remove the field and recreate it with a new field that works as you want. We actually do that for inline editing our forms: we have a readonly form, when you click on a field it becomes editable, at that moment we fully remove the readonly and create a new field and put it were the other was.

Similar Threads

  1. RegEx is failing for valid regex
    By anton.stepan in forum Sencha Ext JS Q&A
    Replies: 2
    Last Post: 16 Sep 2014, 4:16 AM
  2. How to change fieldLabel dynamically
    By MeDigital in forum Sencha Ext JS Q&A
    Replies: 1
    Last Post: 7 May 2012, 12:22 PM
  3. How to set regex in textfield dynamically
    By macap in forum Sencha Ext JS Q&A
    Replies: 1
    Last Post: 28 Mar 2010, 1:22 AM
  4. Dynamically change regex in textfield problem
    By altamirador in forum Ext 3.x: Help & Discussion
    Replies: 6
    Last Post: 18 Aug 2009, 10:07 AM
  5. Ext.Template Regex change request
    By Jens in forum Ext 1.x: Help & Discussion
    Replies: 1
    Last Post: 10 Oct 2007, 10:32 PM

Posting Permissions

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