From ebea2c1d4c6922d054952cdec42c41f97d666c15 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Thu, 12 Jul 2012 10:12:53 +0530 Subject: [PATCH] focus on first element when dialog opens and enter on text triggers submit --- js/legacy/wn/widgets/form/sidebar.js | 2 +- js/wn/ui/dialog.js | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/js/legacy/wn/widgets/form/sidebar.js b/js/legacy/wn/widgets/form/sidebar.js index 56d8f40cfd..8a88671748 100644 --- a/js/legacy/wn/widgets/form/sidebar.js +++ b/js/legacy/wn/widgets/form/sidebar.js @@ -43,7 +43,7 @@ wn.widgets.form.sidebar = { Sidebar: function(form) { label: 'List', icon: 'icon-list', display: function() { - return !me.form.meta.issingle; + return !me.form.meta.issingle && !me.form.meta.read_only; }, onclick: function() { window.location.href="#!List/" + me.form.doctype } }, diff --git a/js/wn/ui/dialog.js b/js/wn/ui/dialog.js index 39131ab095..68aaafac70 100644 --- a/js/wn/ui/dialog.js +++ b/js/wn/ui/dialog.js @@ -49,6 +49,15 @@ wn.widgets.FieldGroup = function() { } } + this.catch_enter_as_submit = function() { + var me = this; + $(this.body).find(':input[type="text"], :input[type="password"]').keypress(function(e) { + if(e.which==13) { + $(me.body).find('.btn-info:first').click(); + } + }) + } + /* get values */ this.get_values = function() { var ret = {}; @@ -119,8 +128,10 @@ wn.widgets.Dialog = function(opts) { this.make_head(); this.body = $a(this.wrapper, 'div', 'dialog_body'); - if(this.opts.fields) + if(this.opts.fields) { this.make_fields(this.body, this.opts.fields); + this.catch_enter_as_submit(); + } } this.make_head = function() { @@ -156,7 +167,7 @@ wn.widgets.Dialog = function(opts) { // show it $ds(this.wrapper); - + // hide background freeze(); @@ -165,6 +176,9 @@ wn.widgets.Dialog = function(opts) { // call onshow if(this.onshow)this.onshow(); + + // focus on first input + $(this.wrapper).find(':input:first').focus(); } this.hide = function() {