得到它的工作,虽然它不是完全干净......在网络浏览器中使用检查我找到了'flowStdEditor'wavemaker对象的dijit ID。我通过输入一个超出范围的值、右键单击工具提示并选择“检查元素”来做到这一点。它向我展示了工具提示的 HTML:
<input aria-invalid="false" style="height: 20px; line-height: 20px;" value="" aria-required="true" aria-disabled="false" aria-valuemax="99.99" aria-valuemin="14.16" tabindex="0" id="dijit_form_NumberTextBox_14" aria-valuenow="88888888888" class="dijitReset dijitInputInner" dojoattachpoint="textbox,focusNode" autocomplete="off" type="text">
我在 html 中使用了id
id="dijit_form_NumberTextBox_14"来执行以下操作:
var flowStdNumBox = dijit.byId("dijit_form_NumberTextBox_14");
alert('flowStdNumBox ' + flowStdNumBox.get("rangeMessage")); // Shows old message
flowStdNumBox.set("rangeMessage",'New Range Message Text');
alert('flowStdNumBox ' + flowStdNumBox.get("rangeMessage")); //Shows new message
一切看起来都不错,当我在数字编辑器小部件中输入超出范围的数字时,它现在显示新消息“新范围消息文本”。
我不喜欢在我的应用程序中硬编码“dijit_form_NumberTextBox_14”。有谁知道为 WaveMaker wm.number 编辑器小部件检索 dijit.id 的方法?(更新!!见下文)
这将检索我需要以编程方式更改工具提示的内容。它将在上面的示例中抓取“dijit_form_NumberTextBox_14”。
var tmp = page[componentName].domNode.childNodes.item(1).attributes.getNamedItem('widgetid');
下面是一些循环遍历所有 wavemaker 页面组件以查找“rangeMessage”和“invalidMessage”属性的代码:
try {
var page = wm.getPage('Main').components;
for(var componentName in page) {
if (typeof page[componentName].domNode != 'undefined') {
if (page[componentName].domNode.childNodes.length >= 2) {
var tmp = page[componentName].domNode.childNodes.item(1).attributes.getNamedItem('widgetid');
if (tmp !== null) {
var id = tmp.value;
var dojoObj = dijit.byId(id);
var rngMsg = dojoObj.get("rangeMessage");
var invalidMsg = dojoObj.get("invalidMessage");
if (typeof rngMsg != 'undefined') {
var compRange = compRngMsg(componentName); // Lookup to see if component has a special range message to use
if (compRange !== null) {
dojoObj.set("rangeMessage",compRange); // Overrides generic rangeMessage set by langTxtRangeMsgVariable
page[componentName].rangeMessage = compRange;
if (debugging) { console.log('Overriding generic rangMessage for ' + componentName + ' to "' + compRange + '"'); }
} else {
dojoObj.set("rangeMessage",app.langTxtRangeMsgVariable.getValue("dataValue"));
page[componentName].rangeMessage = app.langTxtRangeMsgVariable.getValue("dataValue");
if (debugging) { console.log('Setting generic rangMessage for ' + componentName + ' to "' + app.langTxtRangeMsgVariable.getValue("dataValue") + '"'); }
}
}
if (typeof invalidMsg != 'undefined') {
if (invalidMsg !== '$_unset_$') {
var compInvalid = compInvalidMsg(componentName); // Lookup to see if component has a special range message to use
if (compInvalid !== null) {
dojoObj.set("invalidMessage",compInvalid); //Override generic message for component
page[componentName].invalidMessage = compInvalid;
if (debugging) { console.log('Overriding generic invalidMessage for ' + componentName + ' to "' + compInvalid + '"'); }
} else {
dojoObj.set("invalidMessage",app.langTxtInvalidMsgVariable.getValue("dataValue")); //Set generic invalid message
page[componentName].invalidMessage = app.langTxtInvalidMsgVariable.getValue("dataValue");
if (debugging) { console.log('Setting generic invalidMessage for ' + componentName + ' to "' + app.langTxtInvalidMsgVariable.getValue("dataValue") + '"'); }
}
}
}
if (debugging) { console.log(componentName + ' - id: ' + id + ' rngMsg: ' + rngMsg + ' invalideMsg: ' + invalidMsg); }
}
} else {
if (debugging) { console.log('Skipping ' + componentName); }
}
}
}
if (debugging) { console.log('Completed setting generic messages'); }
} catch(errC) {
var msg = 'languageDataVariableResult: Error encounted during generic message converions! ' + errC;
console.log(msg);
app.toastWarning(msg);
}