Files
roll20-character-sheets/backbone/source/scaffold/attribute_holders/_selects.pug
T

66 lines
2.0 KiB
Plaintext

//- @pugdoc
name: select
description: A mixin to create a select element. Uses K-scaffold global variables to control how {@link option} mixins within the select's block behave.
arguments:
- {object} inputObj - The object describing the select
- {block} block - The content within the select
attributes:
example: |
include _htmlelements.pug
+select({name:'my select'})
+option({value:'a value','data-i18n':'a translation key',trigger:{affects:['some_attribute']}})
+option({value:'value 2','data-i18n':'translation 2'})
+option({value:'value 3'})
|Some Text we include via the option's block
mixin select(obj)
- checkKUse();
-
obj.class = obj.class ?
replaceProblems(obj.class) :
undefined;
- obj.name = attrName(obj.name);
- obj.title = obj.title || attrTitle(obj.name);
- obj.name = `attr_${obj.name}`;
- addFieldToFieldsetObj(obj);
//- Initialize the object that will be passed to the cascade
- const triggerObj = {...obj,type:'select'};
- const options = [];
mixin option(optObj)
-
obj.class = obj.class ?
replaceProblems(obj.class) :
undefined;
-
const pushObj = {
obj:optObj,
attributes: attributes || {}
};
if block
- pushObj.block = block;
- options.push(pushObj);
if !block
option(value='!!! Error: empty select !!!')
else
- block();
- const selObj = makeElementObj(obj);
select&attributes(selObj)&attributes(attributes)
each o in options
if o.hasOwnProperty('selected') && o.hasOwnProperty('value')
- triggerObj.value = o.value;
if o.trigger && !triggerObj.trigger
- triggerObj.trigger = o.trigger;
- const elemObj = makeElementObj(o.obj);
option&attributes(elemObj)&attributes(o.attributes)
- storeTrigger(triggerObj);
//- mixin select(obj)
//- select&attributes(obj)
//- if block
//- block
//- else
//- +option({value:'empty select, PEBKAC',selected:true})
//-End Mixin