Results 1 to 3 of 3

Thread: Add Similar Regexp function or Similar in Sencha

  1. #1
    Sencha User
    Join Date
    Apr 2012
    Posts
    36
    Vote Rating
    -2
      0  

    Default Add Similar Regexp function or Similar in Sencha

    I want to add Regexp or similar functionality just like in jquery or PHP to enter only HTTP or number only in textfield of Sencha mean to show error if user doesn't satisfy condition of any Regexp function.How can I implement it?

  2. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,556
    Answers
    3932
    Vote Rating
    1272
      0  

    Default

    You can listen to the keydown event and check against regexp. If it fails stopEvent() on the event object.

    This is a pattern text field that takes a pattern attribute value (HTML5 pattern attrib)

    Code:
    Ext.define('Ux.field.PatternText', {
        extend : 'Ext.field.Text',
        xtype  : 'patterntextfield',
    
        config : {
            pattern : '[0-9]*'
        },
    
        updatePattern : function(pattern) {
            var component = this.getComponent();
    
            component.updateFieldAttribute('pattern', pattern);
        },
    
        initialize : function() {
            this.callParent();
    
            var component = this.getComponent();
    
            component.input.on({
                scope   : this,
                keydown : 'onKeyDown'
            });
        },
    
        onKeyDown : function(e) {
            var code = e.browserEvent.keyCode;
    
            if (!(code >= 48 && code <= 57) && !(code >= 97 && code <= 105) && code !== 46 && code !== 8) {
                e.stopEvent();
            }
        }
    });
    That only allows numbers and keys like delete. In the onKeyDown you can use a RegExp test and if it fails then do the e.stopEvent().
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  3. #3
    Sencha User
    Join Date
    Apr 2012
    Posts
    36
    Vote Rating
    -2
      0  

    Default

    Thanks for Help.Where to add as I have code like this
    Code:
    Ext.define("PlayListApp.view.PlayEditor", {
        extend: "Ext.form.Panel",
        requires: "Ext.form.FieldSet",
        alias: "widget.playeditorview",
         config:{ 
            scrollable: 'vertical',
            items: [
      {
      xtype: 'textfield',
                            name: 'duration',
                            label: 'Duration',
                            placeHolder:'99',  
                            required:true
    }
    And I also want to add max and min value ie 3 and 1 as number field didn't support.Same for adding only links Regexp function or matcher something.

Tags for this Thread

Posting Permissions

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