Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions lib/components/List.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@ var MLList = module.exports = milo.createComponentClass({
},
data: undefined,
events: undefined,
model: undefined,
model: {
messages: {
'*': { subscriber: onListChange, context: 'owner' }
}
},
list: undefined
},
methods: {
init: MLList$init,
destroy: MLList$destroy,
removeItem: MLList$removeItem,
moveItem: MLList$moveItem
moveItem: MLList$moveItem,
setListLimit: MLList$setListLimit,
}
});

Expand Down Expand Up @@ -43,8 +48,21 @@ function MLList$moveItem(from, to) {
return this.model.splice(to, 0, splicedData[0]);
}

function MLList$setListLimit(limit) {
this._listLimit = Number.isInteger(limit) && limit !== 0 && limit;
}


function onChildrenBound() {
this.model.set([]);
this._connector = milo.minder(this.model, '<<<-', this.data).deferChangeMode('<<<->>>');
}

function onListChange(_msg, { type }) {
const { _listLimit, list } = this;
const currentItemCount = list.count();
if(type === 'added' && _listLimit && currentItemCount >= _listLimit){
const diff = Math.abs(currentItemCount - _listLimit) + 1;
list.removeItems(0, diff);
}
}
2 changes: 1 addition & 1 deletion lib/forms/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ var SCHEMA_KEYWORDS = _.object([
'modelPath', 'modelPattern', 'notInModel',
'messages', 'translate', 'validate', 'items',
'selectOptions', 'radioOptions', 'comboOptions',
'comboOptionsURL', 'addItemPrompt', 'placeHolder',
'comboOptionsURL', 'limitComboList', 'addItemPrompt', 'placeHolder',
'value', 'dataValidation', 'asyncHandler', 'autoresize',
'maxLength'
], true);
Expand Down
3 changes: 2 additions & 1 deletion lib/forms/item_types.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,14 @@ function processSuperComboSchema(comp, schema) {


function processComboListSchema(comp, schema) {
const { comboOptions, comboOptionsURL, addItemPrompt, placeHolder } = schema;
const { comboOptions, comboOptionsURL, addItemPrompt, placeHolder, limitComboList } = schema;
_.deferTicks(function() {
if (addItemPrompt) comp.setAddItemPrompt(addItemPrompt);
if (placeHolder) comp.setPlaceholder(placeHolder);
if (!comboOptionsURL) comp.setDataValidation(schema.dataValidation);
setComponentOptions(comp, comboOptions, setComboOptions);
if (comboOptionsURL) comp.container.scope.combo.initOptionsURL(comboOptionsURL);
if (limitComboList) comp.container.scope.list.setListLimit(limitComboList);
}, 2);
}

Expand Down