在上上篇文章中回忆到UAP生成列表和表单,这篇文章就继续记载我在项目中遇到的一些关于uap form的东西
利用UAP生成表单以后输入表单,但是有些数据是不需要在表单中显示出来但是我们还想放到form里面。这样就需要在通过一些代码来进行设置
form表单的内容fileds是页面显示的内容,在目前的UAP版本中设置表单数据不可见需要在java端设置vo里面的字段visible为false同时前端也需要设置visible为false,这一点也是UAP的一个bug。
_dataForm = new mx.datacontrols.DataForm({
displayPrimaryKey: false,
width:"90%",
fields:[{name:"planId",caption:"计划Id", editorType: "TextEditor",visible:false},
{name:"planNum",caption:"计划编号", editorType: "TextEditor"},
{name:"createDate",caption:"月份", editorType: "DateTimeEditor",formatString:"yyyy-MM"},
{name:"planName",caption:"计划名称", editorType: "TextEditor",},
{name:"planType",caption: "类型", editorType : "DropDownEditor",
displayMember:"name",
valueMember:"value",
items : [ {
name : "临时计划",
value : "1"
}, {
name : "月度计划",
value : "2"
}]},
{name:"planMemo",caption:"计划说明", editorType: "TextEditor"}
],
entityContainer:formEntityContainer
});
_dataForm.entityContainer.on("saved", me.controller._savePlanItem);
_dataForm.on("validate", function(e) {
var entityContainer = _dataForm.entityContainer;
var planName = entityContainer.getValue("planName");
var planNameReg =new RegExp(/^[\u4e00-\u9fa5\w]{0,50}$/).test(planName)
if(!planNameReg){
e.successful = false;
e.hint = "计划名称的中不要特殊字符,长度不能超过25!";
}
if (entityContainer.getValue("createDate") == null) {
e.successful = false;
e.hint = "请选择类型!";
}
if (entityContainer.getValue("planType") == null) {
e.successful = false;
e.hint = "请选择类型!";
}
var planMemo = entityContainer.getValue("planMemo");
if(planMemo !=null){
var planMemoReg =new RegExp(/^[\u4e00-\u9fa5\w]{100}$/).test(planMemo)
if(entityContainer.getValue("planMemo") == null ){
e.successful = false;
e.hint = "计划说明输入的字符不能不能含特殊字符,不能大于100!";
}
}
});
name相当于Id,caption就是显示的名称,editorType是控件类型,TextEditor是输入框,DropDownEditor则是下拉选项框
editorType: "DateTimeEditor",formatString:"yyyy-MM" 表示该控件是时间控件,选中后显示的值是yyyy-mm类型
_dataForm.entityContainer.on("saved", me.controller._savePlanItem);这段代码的意识是在调用dataform的保存方法以后在去调用me.controller._savePlanItem的方法
DataForm的validate方法
validate(p_data, [p_withoutIndication]) 方法
参数
- p_data
待校验的表单数据。
- p_withoutIndication
可选的。默认值为“false”。指定是否需要采用提示。
按照UAP的规则,form的保存和赋值都在controller端
首先在MainView端获取到form表单
/**
* 获取表单视图窗口对象
*/
me.getDetailWindow = function(){
return _detailWin;
}
在controller端的save方法:
me._btnSave_onclick = function()
{
var planNum = me.view.getForm().entityContainer.getValue("planNum");
me.view.getForm().entityContainer.setValue("planNum", planNum, true);
me.view.getForm().save();
};
form表单的实体容器是mx.datacontainers.FormEntityContainer,所以获取和塞入数据的时候都要通过它的entityContainer方法进行赋值和取值。
当然form里面还有一些方法和属性这写就需要看API来使用了。