editor.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. Ext.require([
  2. 'Ext.Editor',
  3. 'Ext.form.Panel',
  4. 'Ext.form.field.ComboBox',
  5. 'Ext.form.field.Date'
  6. ]);
  7. Ext.onReady(function(){
  8. Ext.create('Ext.form.Panel', {
  9. renderTo: 'container',
  10. width: 700,
  11. height: 400,
  12. title: 'User Details',
  13. defaultType: 'textfield',
  14. bodyPadding: 10,
  15. defaults: {
  16. labelWidth: 100
  17. },
  18. items: [{
  19. fieldLabel: 'First Name',
  20. name: 'firstname'
  21. }, {
  22. fieldLabel: 'Middle Name',
  23. name: 'middlename'
  24. }, {
  25. fieldLabel: 'Last Name',
  26. name: 'lastname'
  27. }, {
  28. xtype: 'datefield',
  29. name: 'dob',
  30. fieldLabel: 'D.O.B'
  31. }],
  32. listeners: {
  33. afterrender: function(form){
  34. var cfg = {
  35. shadow: false,
  36. completeOnEnter: true,
  37. cancelOnEsc: true,
  38. updateEl: true,
  39. ignoreNoChange: true
  40. }, height = form.child('textfield').getHeight();
  41. var labelEditor = Ext.create('Ext.Editor', Ext.apply({
  42. autoSize: {
  43. width: 'field'
  44. },
  45. height: height,
  46. offsets: [0, (Ext.isIEQuirks ? 0 : 2)],
  47. alignment: 'l-l',
  48. listeners: {
  49. beforecomplete: function(ed, value){
  50. if (value.charAt(value.length - 1) != ':') {
  51. ed.setValue(ed.getValue() + ':');
  52. }
  53. return true;
  54. }
  55. },
  56. field: {
  57. width: 100,
  58. name: 'labelfield',
  59. allowBlank: false,
  60. xtype: 'textfield',
  61. selectOnFocus: true,
  62. maxLength: 20,
  63. enforceMaxLength: true
  64. }
  65. }, cfg));
  66. form.body.on('dblclick', function(e, t){
  67. labelEditor.startEdit(t);
  68. // Manually focus, since clicking on the label will focus the text field
  69. labelEditor.field.focus(50, true);
  70. }, null, {
  71. delegate: 'label.x-form-item-label'
  72. });
  73. var titleEditor = Ext.create('Ext.Editor', Ext.apply({
  74. alignment: 'tl',
  75. offsets: [0, -3],
  76. field: {
  77. width: 130,
  78. xtype: 'combo',
  79. editable: false,
  80. forceSelection: true,
  81. queryMode: 'local',
  82. displayField: 'text',
  83. valueField: 'text',
  84. store: {
  85. fields: ['text'],
  86. data: [{
  87. text: 'User Details'
  88. },{
  89. text: 'Developer Details'
  90. },{
  91. text: 'Manager Details'
  92. }]
  93. }
  94. }
  95. }, cfg));
  96. form.header.titleCmp.textEl.on('dblclick', function(e, t){
  97. titleEditor.startEdit(t);
  98. });
  99. }
  100. }
  101. });
  102. });