-
25 Jun 2012 5:47 AM #1
stopEvent fails to prevent blur when custom trigger field is invalid.
stopEvent fails to prevent blur when custom trigger field is invalid.
REQUIRED INFORMATION
Ext version tested:- Ext 4.1.1 rev RC2
- Ext 4.1
- Ext 4
- Chrome 19
- IE 9
- FF 13 (Firebug 1.9.2b2 installed)
- Safari 5.1.7
- HTML 5
- We have a custom trigger control that peforms validation via asynchronous Ajax request on blur. If the field is valid, the focus changes to the new field. If the field is invalid, however, we do not want the focus to change.
- When tabbing in FF, the focus moves to the next field, ignoring the stopEvent call.
- Type any value in the Trigger field and press tab.
- The focus should stay in the Trigger field.
- The focus moves to the next field.
- Again, this is a Firefox-ONLY issue.
Content of Ajax response:Code:Ext.require([ 'Ext.form.*', 'Ext.button.Button', 'Ext.Ajax' ]); Ext.define('Test.CustomTrigger', { extend: 'Ext.form.field.Trigger', alias: 'widget.customtrigger', initComponent : function() { var me = this; Ext.apply(me, { validator: me.onValidate, enableKeyEvents: true }); me.callParent(); }, checkTab: function(me, e) { if (!this.ignoreMonitorTab && e.getKey() == e.TAB) { if (!me.isValid()) { e.stopEvent(); return; } me.triggerBlur(); } }, validateBlur: function(e) { var me = this, value = me.getValue(), valid = true; if (!me.isValid()) { valid = false; console.log('field is invalid'); me.focus(); } return valid; }, onValidate: function(value) { var responseData; Ext.Ajax.request({ url: 'data.json', async: false, success: function(response){ responseData = Ext.decode(response.responseText); } }); if (responseData.valid === true) { return true; } else { return 'Invalid value'; } } }); Ext.onReady(function() { var required = '<span style="color:red;font-weight:bold" data-qtip="Required">*</span>'; var form = Ext.widget({ xtype: 'form', layout: 'form', collapsible: true, id: 'simpleForm', url: 'save-form.php', frame: true, title: 'Simple Form', bodyPadding: '5 5 0', width: 500, fieldDefaults: { msgTarget: 'side', labelWidth: 75, validateOnBlur: true }, defaultType: 'textfield', items: [{ fieldLabel: 'First Name', afterLabelTextTpl: required, name: 'first', allowBlank:false },{ fieldLabel: 'Last Name', afterLabelTextTpl: required, name: 'last' },{ fieldLabel: 'Company', name: 'company' }, { fieldLabel: 'Email', afterLabelTextTpl: required, name: 'email', vtype:'email' }, { fieldLabel: 'Trigger', name: 'trigger', xtype: 'customtrigger', afterLabelTextTpl: required, allowBlank: false, validateOnBlur: false, validateOnChange: false }, { fieldLabel: 'Age', name: 'age', xtype: 'numberfield', minValue: 0, maxValue: 100 }, { xtype: 'timefield', fieldLabel: 'Time', name: 'time', minValue: '8:00am', maxValue: '6:00pm' }], buttons: [{ text: 'Save' },{ text: 'Cancel' }] }); form.render(document.body); });
Code:{ "valid": false }
HELPFUL INFORMATION
Operating System:- Win7 Enterprise
Last edited by dlamee; 25 Jun 2012 at 5:57 AM. Reason: Made a little more clear this is a Firefox only issue.
-
27 Jun 2012 7:11 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,714
- Vote Rating
- 438
This works on my FF13 for Mac. I typed 'text' in the Trigger field and tabbed and it kept focus on the Trigger field and marked it as invalid.
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
28 Jun 2012 10:15 AM #3
Just tested on Firefox for Windows and this IS an issue.
-
28 Jun 2012 1:47 PM #4
I can reproduce this on Windows, but without researching I'm not really sure if there's a great deal we can do with it, will need to look into it further.
Evan Trimboli
Sencha Developer
Twitter - @evantrimboli
Don't be afraid of the source code!
-
28 Jun 2012 2:24 PM #5
Yeah, looks like it's a FF bug, it seems as though it will fire the focus regardless:
There's an existing issue: https://bugzilla.mozilla.org/show_bug.cgi?id=489375Code:function createField(id) { var field = document.createElement('input'); field.type = 'text'; field.id = id; field.name = name; document.body.appendChild(field); return field; } document.addEventListener('DOMContentLoaded', function(){ var f1 = createField('f1'), f2 = createField('f2'); f1.addEventListener('keydown', function(e){ if (e.keyCode === 9) { var xhr = new XMLHttpRequest(); xhr.open('GET', 'data.json', false); xhr.send(null); if (xhr.responseText == 'fail') { e.preventDefault(); } xhr = null; } }, false); });
I'll bump it with my test case.Evan Trimboli
Sencha Developer
Twitter - @evantrimboli
Don't be afraid of the source code!
-
29 Jun 2012 5:35 AM #6
Looks like we can't reproduce the issue or there's a problem in the test case provided.


Reply With Quote