This repository has been archived by the owner on Jul 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
UIModel
Adarsh Pastakia edited this page Mar 24, 2017
·
3 revisions
-
serialize(Object)
: Return simple JSON object, child properties with Arrays will be converted to comma separated strings
import {UIModel} from 'aurelia-ui-framework';
import {ValidationRules} from "aurelia-validation";
export class MyModel extends UIModel {
firstName:string = '';
lastName:string = '';
age:number = 0;
email:string = '';
allowCalls:boolean = false;
mobilePhone:string = '';
constructor() {
super();
ValidationRules
.ensure((m:MyModel)=>m.firstName)
.required()
.maxLength(49)
.ensure(m=>m.lastName)
.required()
.maxLength(49)
.ensure(m=>m.email)
.required()
.email()
.ensure(m=>m.age)
.required()
.satisfiesRule('number', 18, 99)
.withMessage('Must be over 18')
.ensure(m=>m.mobilePhone)
.required()
.when(m => m.allowCalls)
.satisfiesRule('phone')
.on(this);
}
post() {
return this.httpClient.post('url', this.serialize());
}
}
export class MyView {
model;
constructor() {
this.model = new MyModel();
}
}
-
logger
: Aurelia Logger instance -
httpClient
: UIHttpService instance
-
Override the following method for individual models
get()
post()
put()
delete()
-
deserialize(JSON)
-
serialize():JSON
-
isDirty():boolean
-
saveChanges()
-
discardChanges()
-
addObserver(UIEvent.observe(...))
: Add to observer collection which will be disposed when disposing the model -
dispose()
- UIButton
- UIFieldset
- UIForm
- UIInputGroup
- UIInput
- UITextarea
- UIDate
- UIPhone
- UICheckbox
- UIRadio
- UISwitch
- UICombo
- UITag
- UIList
- UIReorder
- UILanguage
- UIMarkdown
- UIDrawer
- UIDropdown
- UIMenu
- UIPanel
- UISidebar
- UIStatsbar
- UIToolbar
- UIDialog
- UITab
- UITree
- UIDatagrid