PageRenderTime 70ms CodeModel.GetById 25ms app.highlight 15ms RepoModel.GetById 13ms app.codeStats 0ms

/ext-4.0.7/examples/form/adv-vtypes.js

https://bitbucket.org/srogerf/javascript
JavaScript | 135 lines | 97 code | 13 blank | 25 comment | 12 complexity | cf25ed414b011f48e63649cd73a9b219 MD5 | raw file
  1/*
  2
  3This file is part of Ext JS 4
  4
  5Copyright (c) 2011 Sencha Inc
  6
  7Contact:  http://www.sencha.com/contact
  8
  9GNU General Public License Usage
 10This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file.  Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
 11
 12If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
 13
 14*/
 15Ext.require([
 16    'Ext.form.*'
 17]);
 18
 19Ext.onReady(function() {
 20
 21    // Add the additional 'advanced' VTypes
 22    Ext.apply(Ext.form.field.VTypes, {
 23        daterange: function(val, field) {
 24            var date = field.parseDate(val);
 25
 26            if (!date) {
 27                return false;
 28            }
 29            if (field.startDateField && (!this.dateRangeMax || (date.getTime() != this.dateRangeMax.getTime()))) {
 30                var start = field.up('form').down('#' + field.startDateField);
 31                start.setMaxValue(date);
 32                start.validate();
 33                this.dateRangeMax = date;
 34            }
 35            else if (field.endDateField && (!this.dateRangeMin || (date.getTime() != this.dateRangeMin.getTime()))) {
 36                var end = field.up('form').down('#' + field.endDateField);
 37                end.setMinValue(date);
 38                end.validate();
 39                this.dateRangeMin = date;
 40            }
 41            /*
 42             * Always return true since we're only using this vtype to set the
 43             * min/max allowed values (these are tested for after the vtype test)
 44             */
 45            return true;
 46        },
 47
 48        daterangeText: 'Start date must be less than end date',
 49
 50        password: function(val, field) {
 51            if (field.initialPassField) {
 52                var pwd = field.up('form').down('#' + field.initialPassField);
 53                return (val == pwd.getValue());
 54            }
 55            return true;
 56        },
 57
 58        passwordText: 'Passwords do not match'
 59    });
 60
 61    /*
 62     * ================  Date Range  =======================
 63     */
 64
 65    var dr = Ext.create('Ext.FormPanel', {
 66        renderTo: 'dr',
 67        frame: true,
 68        title: 'Date Range',
 69        bodyPadding: '5px 5px 0',
 70        width: 350,
 71        fieldDefaults: {
 72            labelWidth: 125,
 73            msgTarget: 'side',
 74            autoFitErrors: false
 75        },
 76        defaults: {
 77            width: 300
 78        },
 79        defaultType: 'datefield',
 80        items: [
 81            {
 82                fieldLabel: 'Start Date',
 83                name: 'startdt',
 84                id: 'startdt',
 85                vtype: 'daterange',
 86                endDateField: 'enddt' // id of the end date field
 87            },
 88            {
 89                fieldLabel: 'End Date',
 90                name: 'enddt',
 91                id: 'enddt',
 92                vtype: 'daterange',
 93                startDateField: 'startdt' // id of the start date field
 94            }
 95        ]
 96    });
 97
 98
 99    /*
100     * ================  Password Verification =======================
101     */
102
103    var pwd = Ext.create('Ext.FormPanel', {
104        renderTo: 'pw',
105        frame: true,
106        title: 'Password Verification',
107        bodyPadding: '5px 5px 0',
108        width: 350,
109        fieldDefaults: {
110            labelWidth: 125,
111            msgTarget: 'side',
112            autoFitErrors: false
113        },
114        defaults: {
115            width: 300,
116            inputType: 'password'
117        },
118        defaultType: 'textfield',
119        items: [
120            {
121                fieldLabel: 'Password',
122                name: 'pass',
123                id: 'pass'
124            },
125            {
126                fieldLabel: 'Confirm Password',
127                name: 'pass-cfrm',
128                vtype: 'password',
129                initialPassField: 'pass' // id of the initial password field
130            }
131        ]
132    });
133
134});
135