UAP form表单取值,赋值及保存

   在上上篇文章中回忆到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]) 方法

执行验证表单的逻辑。 返回一个对象(如 { successful: true }),该对象的 successful 属性表示该表单通过验证;如果返回对象为 { successful: false, hint: "描述错误原因。", fieldName: "错误字段名称" },其中 fieldName 是可选字段,是出错字段的 FormField.name,原因由 hint 描述。 该方法将触发 onvalidate 事件, 可通过该事件进行自定义数据校验,详见该事件示例。
参数
  • 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来使用了。

 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值