如何将文本字段设置为 'required',然后在 Maximo Anywhere 应用程序中突出显示所有内容
How to set text fields to 'required' then highlight all in a Maximo Anywhere app
这更像是一个方法。我想通了并决定分享,因为我在任何地方都找不到其他 doco。这将遍历所有必填字段,突出显示空字段并从已填写的字段中删除突出显示。它将把焦点放在它找到的第一个空字段上。
注意:一旦离开视图或显示弹出对话框,焦点就会丢失,因此任何“throw new PlatformRuntimeWarning('blah');”应删除紧随此新代码之后的语句。
处理程序代码:
define("application/handlers/WhatEverHandler",
[ …
"dojo/query",
"dojo/dom",
"dojo/dom-style",
…],
function(…query, dom, domStyle, …)
workLog.getRuntimeFieldMetadata('reading').set('required',true);
workLog.getRuntimeFieldMetadata('reading1’).set('required',true);
…
var mainNode = dom.byId("body");
var nodes = query(".requiredText", mainNode);
var firstemptynode = true;
for (var nodecount = 0; nodecount < nodes.length; nodecount++) {
if (nodes[nodecount].value === ""){
domStyle.set(nodes[nodecount], "borderBottom", "10px solid red");
domStyle.set(nodes[nodecount], "background-color", "rgba(240, 147, 153, 0.5”);
if (firstemptynode){
nodes[nodecount].focus();
firstemptynode = false;
};
}else{
domStyle.set(nodes[nodecount], "borderBottom", "");
domStyle.set(nodes[nodecount], "background-color", "");
};
};
如果该字段在 app.xml 中没有标签,则您不能将其设置为必填项,因为该属性未定义。相反,您可以在 app.xml 中的文本项上定义一个空的 cssClass 您想要使其成为必需的属性,然后在查询中搜索 class 而不是 "requiredText",例如
artifact/app.xml:
<text cssClass="myReqTextBox" editable="true" placeHolder="Please Enter" id="WorkExecution.WorkDetailView_workOrder_groupitem_inst_Install4" resourceAttribute="reading" layoutInsertAt="itemReading1”/>
common/css/mdpi.css:
.myReqTextBox {
}
然后在代码中删除
workLog.getRuntimeFieldMetadata(‘<attribute>').set('required',true);
行并将 dom 节点查询更新为
var nodes = query(“.myReqTextBox", mainNode);
当然,如果您想应用一些非动态样式,您可以在此 class.
中静态设置它们
这是一个可行的解决方案 - comments/experience 不过很感激。
这更像是一个方法。我想通了并决定分享,因为我在任何地方都找不到其他 doco。这将遍历所有必填字段,突出显示空字段并从已填写的字段中删除突出显示。它将把焦点放在它找到的第一个空字段上。 注意:一旦离开视图或显示弹出对话框,焦点就会丢失,因此任何“throw new PlatformRuntimeWarning('blah');”应删除紧随此新代码之后的语句。
处理程序代码:
define("application/handlers/WhatEverHandler",
[ …
"dojo/query",
"dojo/dom",
"dojo/dom-style",
…],
function(…query, dom, domStyle, …)
workLog.getRuntimeFieldMetadata('reading').set('required',true);
workLog.getRuntimeFieldMetadata('reading1’).set('required',true);
…
var mainNode = dom.byId("body");
var nodes = query(".requiredText", mainNode);
var firstemptynode = true;
for (var nodecount = 0; nodecount < nodes.length; nodecount++) {
if (nodes[nodecount].value === ""){
domStyle.set(nodes[nodecount], "borderBottom", "10px solid red");
domStyle.set(nodes[nodecount], "background-color", "rgba(240, 147, 153, 0.5”);
if (firstemptynode){
nodes[nodecount].focus();
firstemptynode = false;
};
}else{
domStyle.set(nodes[nodecount], "borderBottom", "");
domStyle.set(nodes[nodecount], "background-color", "");
};
};
如果该字段在 app.xml 中没有标签,则您不能将其设置为必填项,因为该属性未定义。相反,您可以在 app.xml 中的文本项上定义一个空的 cssClass 您想要使其成为必需的属性,然后在查询中搜索 class 而不是 "requiredText",例如
artifact/app.xml:
<text cssClass="myReqTextBox" editable="true" placeHolder="Please Enter" id="WorkExecution.WorkDetailView_workOrder_groupitem_inst_Install4" resourceAttribute="reading" layoutInsertAt="itemReading1”/>
common/css/mdpi.css:
.myReqTextBox {
}
然后在代码中删除
workLog.getRuntimeFieldMetadata(‘<attribute>').set('required',true);
行并将 dom 节点查询更新为
var nodes = query(“.myReqTextBox", mainNode);
当然,如果您想应用一些非动态样式,您可以在此 class.
中静态设置它们这是一个可行的解决方案 - comments/experience 不过很感激。