From 6252e27f6c2f75bdc55f3585b60f2d75220d6df7 Mon Sep 17 00:00:00 2001 From: j Date: Sun, 3 Sep 2023 11:44:49 +0100 Subject: [PATCH] Ox.FormPanel: support setting inital and updating selected panel --- source/UI/js/Form/FormPanel.js | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/source/UI/js/Form/FormPanel.js b/source/UI/js/Form/FormPanel.js index 63755307..ca9f22f2 100644 --- a/source/UI/js/Form/FormPanel.js +++ b/source/UI/js/Form/FormPanel.js @@ -15,11 +15,18 @@ Ox.FormPanel = function(options, self) { var that = Ox.Element({}, self) .defaults({ form: [], - listSize: 256 + listSize: 256, + section: null }) - .options(options || {}); + .options(options || {}) + .update({ + section: setSection + }); - self.section = 0; + if (self.options.section === null) { + self.options.section = self.options.form[0].id; + } + self.section = Ox.getIndexById(self.options.form, self.optoins.section); self.sectionTitle = self.options.form[self.section].title; self.$list = Ox.TableList({ columns: [ @@ -62,7 +69,7 @@ Ox.FormPanel = function(options, self) { }), max: 1, min: 1, - selected: [self.options.form[0].id], + selected: [self.options.selected], sort: [{key: 'id', operator: '+'}], unique: 'id', width: self.options.listSize @@ -130,7 +137,18 @@ Ox.FormPanel = function(options, self) { }); }); - self.$sections[0].show(); + self.$sections[self.section].show(); + + function setSection() { + var id = self.options.section, + section = Ox.getIndexById(self.options.form, id); + if (self.section != section) { + self.$sections[self.section].hide(); + self.section = section; + self.$list.options('selected', [id]); + self.$sections[self.section].show(); + } + }; that.setElement(Ox.SplitPanel({ elements: [