Skip to content
Snippets Groups Projects

FIX: auto_focus on forms without forms

Merged Florian Spreckelsen requested to merge f-autofocus-on-empty-form into dev
All threads resolved!
3 files
+ 60
20
Compare changes
  • Side-by-side
  • Inline
Files
3
+ 13
12
@@ -26,7 +26,7 @@
* form_panel module for creating a panel below the navbar where forms can be
* placed.
*/
var form_panel = new function () {
var form_panel = new function() {
const logger = log.getLogger("form_panel");
this.version = "0.1";
this.dependencies = ["log", "caosdb_utils", "markdown", "bootstrap"];
@@ -38,7 +38,7 @@ var form_panel = new function () {
* 1. Creates the form panel if it does not exist.
* 2. Removes the welcome panel if present.
*/
this.get_form_panel = function (panel_id, title) {
this.get_form_panel = function(panel_id, title) {
// remove welcome
$(".caosdb-f-welcome-panel").remove();
$(".caosdb-v-welcome-panel").remove();
@@ -60,7 +60,7 @@ var form_panel = new function () {
/**
* Remove the form panel from the DOM tree.
*/
this.destroy_form_panel = function (panel) {
this.destroy_form_panel = function(panel) {
$(panel).remove();
};
@@ -75,22 +75,22 @@ var form_panel = new function () {
* The first input element will be focused unless you specify `false` as
* fifths parameter.
*/
this.create_show_form_callback = function (
panel_id, title, form_config, form_creator=undefined, auto_focus=true
this.create_show_form_callback = function(
panel_id, title, form_config, form_creator = undefined, auto_focus = true
) {
return (e) => {
logger.trace("enter show_form_panel", e);
const panel = $(form_panel.get_form_panel(panel_id, title));
if (panel.find("form").length === 0) {
if (form_config != undefined && form_creator!=undefined){
if (form_config != undefined && form_creator != undefined) {
throw new Error("create_show_form_callback takes either a FormConfig or a function that creates the form");
}
var form;
if (form_config != undefined ){
if (form_config != undefined) {
form = form_elements.make_form(form_config);
} else if (form_creator != undefined ){
} else if (form_creator != undefined) {
form = form_creator();
} else {
throw new Error("create_show_form_callback takes a FormConfig or a function that creates the form");
@@ -104,17 +104,18 @@ var form_panel = new function () {
);
}
if (typeof auto_focus === "undefined" || !!auto_focus === true) {
if (panel.find("form")[0].length>0) {
if (panel.find("form").length > 0 && panel.find("form")[0].length > 0) {
panel.find("form")[0][0].focus();
} else {
logger.debug("create_show_form_callback was called with auto_focus = true (default), but no form is given.");
}
}
}
};
this.init = function () {
}
this.init = function() {}
}
$(document).ready(function () {
$(document).ready(function() {
caosdb_modules.register(form_panel);
});
Loading