Skip to content

Commit 8f74596

Browse files
committed
add fieldset widget
1 parent 81bff2e commit 8f74596

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

lib/glow/primitives.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3037,6 +3037,42 @@
30373037
return cradio
30383038
}
30393039

3040+
function fieldset(args) { // a form fieldset
3041+
if (!(this instanceof fieldset)) return new fieldset(args) // so fieldset() is like new fieldset()
3042+
var cvs = canvas.get_selected()
3043+
var attrs = {pos:cvs.caption_anchor, legend:'', width:cvs.width}
3044+
3045+
for (a in attrs) {
3046+
if (args[a] !== undefined) {
3047+
attrs[a] = args[a]
3048+
delete args[a]
3049+
}
3050+
}
3051+
3052+
let fs_css = {width:`${attrs.width}px`}
3053+
attrs.jfieldset = $('<fieldset>').css(fs_css).appendTo(attrs.pos)
3054+
$(`<legend>${attrs.legend}</legend>`).appendTo(attrs.jfieldset)
3055+
3056+
var cfieldset = { // this structure implements a JavaScript "closure"
3057+
get legend() {
3058+
if (attrs.legend === undefined) return ""
3059+
return attrs.legend
3060+
},
3061+
set legend(value) {
3062+
throw new Error("Cannot change a fieldsets legend.")
3063+
},
3064+
get pos() {
3065+
return attrs.jfieldset
3066+
},
3067+
set pos(value) {
3068+
throw new Error("Cannot change a fieldsets pos.")
3069+
}
3070+
}
3071+
3072+
return cfieldset
3073+
}
3074+
3075+
30403076
function checkbox(args) { // a checkbox
30413077
if (!(this instanceof checkbox)) return new checkbox(args) // so checkbox() is like new checkbox()
30423078
var cvs = canvas.get_selected()
@@ -3683,6 +3719,7 @@
36833719
wtext: wtext,
36843720
winput: winput,
36853721
radio: radio,
3722+
fieldset:fieldset,
36863723
checkbox: checkbox,
36873724
button: button,
36883725
slider: slider,

0 commit comments

Comments
 (0)