打算写的时候变成这样子
<ui-form rules="{{rules}}">
<ui-formitem><input type="text" name="name" /></ui-formitem>
<ui-formitem><input type="password" name="password" /></ui-formitem>
</ui-form>
其中
var Form = san.defineComponent({
template: '<form class="san-form"><slot/></form>',
messages: {
'form-element-changed': function (arg) {
var rules = this.data.get('rules');
// TODO
}
},
attached: function () {
// TODO
}
});
var FormItem = san.defineComponent({
template: '<div class="san-form-item"><slot/></div>',
attached: function () {
var self = this;
var child = this.slotChilds[0].childs[0];
var name = child.evalExpr(child.props.get('name').expr));
if (!name) {
return;
}
if (isComponent(child)) {
child.on('input', function () {
self.dispatch('form-element-changed', {
name: name,
value: child.evalExpr(child.props.get('value').expr))
});
});
}
else {
child._onEl('input', function () {
self.dispatch('form-element-changed', {
name: name,
value: child.el.value
});
});
}
}
});