Servoy / svyKeyListener

NG Service for sending key strokes to the server
MIT License
0 stars 1 forks source link

Return element name to key listener callback. #2

Closed iangus closed 6 years ago

iangus commented 6 years ago

Currently the key listener returns the element value to the callback function, but there is no way to find what element the value is from.

By returning the element name, it allows the RuntimeComponent to be found in servoy using elements[elementName]. This then allows the returned key listener value to be checked against the current servoy value for any changes.

Requested change in keylistener.js line 28 $window.executeInlineScript(callback.formname, callback.script,[$element.val()]); change to $window.executeInlineScript(callback.formname, callback.script,[$element.val(),$element[0].name]);

Example use:

function checkChanges(newValue, fieldName){
    // Get the field the key listener fired on.
    var field = elements[fieldName];
    var dataProviderID = field.getDataProviderID();
    var currentValue = foundset.getDataProviderValue(dataProviderID);

    if(currentValue != newValue){
            // Changes detected.
        }else {
            // No changes.
        }
}
meraedit commented 6 years ago

I added a js event to the callback function, and you can get more info from the event. Now your checkChanges function would look like:

function checkChanges(newValue, event){ // Get the field the key listener fired on. var field = elements[event.getElementName()]; var dataProviderID = field.getDataProviderID(); var currentValue = foundset.getDataProviderValue(dataProviderID); if(currentValue != newValue){ // Changes detected. }else { // No changes. } }