Modifying rangeMessage on wm.Number editor widget

113 Views Asked by At

I have a WaveMaker 6.7 app where I need to change the dojo ToolTip object for the rangeMessage property. For example, the javascript below changes the 'rangeMessage' property of a wavemaker number editor widget:

var page = wm.getPage('Main');
page["flowStdEditor"].setValue('rangeMessage','New Range Message Text');
alert(page["flowStdEditor"].rangeMessage); // Shows 'New Range Message Text' set above

On data entry where I enter a number that is out of range, I still receive the old 'rangeMessage' from when the app first started up in the clients web browser. Any ideas on how to change the 'rangeMessage' property on a number editor widget dynamically?? or after changing the 'rangeMessage' property, how do I refresh the dojo ToolTip object so it picks up the latest text??

Thx!!

1

There are 1 best solutions below

0
GoinOff On BEST ANSWER

Got it working, although it's not completely clean... using inspect in the web browser I found the dijit ID for the 'flowStdEditor' wavemaker object. I did this by entering a value out of range, right-clicking the tooltip and selecting 'inspect element'. It showed me the HTML for the tooltip:

<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">

I used id id="dijit_form_NumberTextBox_14" in the html to do the following:

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

Everything looks OK and when I enter a number that is out of ranged in the number editor widget, it now shows the new message 'New Range Message Text'.

What I don't like is hard coding the 'dijit_form_NumberTextBox_14' in my app. Does anyone know a way of retrieving the dijit.id for a WaveMaker wm.number editor widget?? (Updated!! See below)

This will retrieve what I need to make the tooltip change programmatically. It will grab 'dijit_form_NumberTextBox_14' in the example sited above.

var tmp = page[componentName].domNode.childNodes.item(1).attributes.getNamedItem('widgetid');

Here is some code that loops through all the wavemaker page components looking for 'rangeMessage' and 'invalidMessage' properties:

    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);
    }