Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.

Moderator: amosbatto

#824238
Hi

I've been reported that typing in a currency field ends up entering the same key twice
ex:
typing '1' ends up as '11',
typing '12' ends up as '1122'
then typing '12' + backspace ends up as '11',

Here is the definition of my field
<SALARY_PAID type="currency" comma_separator="." mask="###,###,###,###.##" required="1" readonly="0" hint="Salary" size="15" mode="edit" btn_cancel="Cancel">

Here are the events which gets automatically generated by PM
blur
Code: Select all
function() {
  return oThis.apply(Class, argumentsToArray(arguments).concat(args));
}
change
Code: Select all
function(event) {
  var tempValue;
  if (me.dependentFields.length === 0) return true;
  var fields = [],
    Fields = [],
    i, grid = '',
    row = 0;
  var gridField = "";
  for (i in me.dependentFields) {
    if (me.dependentFields[i].dependentOf) {
      for (var j = 0; j < me.dependentFields[i].dependentOf.length; j++) {
        var oAux = me.dependentFields[i].dependentOf[j];
        if (oAux.name.indexOf('][') > -1) {
          var arrayAux = oAux.name.split("][");
          grid = arrayAux[0];
          row = parseInt(arrayAux[1]);
          fieldName = arrayAux[2];
          gridField = gridGetAllFieldAndValue(oAux.name, 0);
          if (Fields.length > 0) {
            aux = Fields;
            aux.push('?');
            if (aux.join('*').indexOf(fieldName + '*') == -1) {
              Fields.push(fieldName);
              eval("var oAux2 = {" + fieldName + ":'" + oAux.value() + "'}");
              fields = fields.concat(oAux2);
            }
          } else {
            Fields.push(fieldName);
            eval("var oAux2 = {" + fieldName + ":'" + oAux.value() + "'}");
            fields = fields.concat(oAux2);
          }
        } else {
          aux = Fields;
          aux.push('?');
          oAux = me.dependentFields[i].dependentOf[0];
          if (Fields.length > 0) {
            if (aux.join('*').indexOf(oAux.name + '*') == -1) {
              Fields.push(oAux.name);
              fields = fields.concat(me.dependentFields[i].dependentOf);
            }
          } else {
            Fields.push(oAux.name);
            fields = fields.concat(me.dependentFields[i].dependentOf);
          }
        }
      }
    }
  }
  var callServer;
  callServer = new leimnud.module.rpc.xmlhttp({
    url: me.form.ajaxServer,
    async: false,
    method: "POST",
    args: "function=reloadField" + "&form=" + encodeURIComponent(me.form.id) + "&fields=" + encodeURIComponent(fields.toJSONString()) + ((grid != "") ? "&grid=" + grid + ((gridField != "") ? "&gridField=" + encodeURIComponent("{" + gridField + "}") : "") : "") + ((row > 0) ? "&row=" + row : "")
  });
  callServer.make();
  var response = callServer.xmlhttp.responseText;
  if (response.substr(0, 1) === '[') {
    var newcont;
    eval('newcont=' + response + ';');
    if (grid == '') {
      for (var i = 0; i < newcont.length; i++) {
        var j = me.form.getElementIdByName(newcont[i].name);
        if (typeof(me.form.aElements[j]) != 'undefined') {
          me.form.aElements[j].setValue(newcont[i].value);
          me.form.aElements[j].setContent(newcont[i].content);
          me.form.aElements[j].updateDepententFields();
        }
      }
    } else {
      for (var i = 0; i < newcont.length; i++) {
        var oAux = me.form.getElementByName(grid);
        if (oAux) {
          var oAux2 = oAux.getElementByName(row, newcont[i].name);
          if (oAux2) {
            oAux2.setValue(newcont[i].value);
            oAux2.setContent(newcont[i].content);
            oAux2.updateDepententFields();
          }
        }
      }
    }
  } else {
    alert('Invalid response: ' + response);
  }
  return true;
}
keydown
Code: Select all
function(event) {
  if (me.element.readOnly) {
    return true;
  }
  if (me.validate == 'Any' && me.mask == '') return true;
  var pressKey = (window.event) ? window.event.keyCode : event.which;
  switch (pressKey) {
    case 8:
    case 46:
    case 35:
    case 36:
    case 37:
    case 38:
    case 39:
    case 40:
      if ((pressKey == 8 || pressKey == 46) && me.validate == "NodeName") {
        return true;
      }
      if (pressKey == 46 && me.validate == "Email") {
        return true;
      }
      me.applyMask(pressKey);
      if ((pressKey == 8 || pressKey == 46) && (me.validate != 'Login' && me.validate != 'NodeName')) me.sendOnChange();
      me.checkBrowser();
      if (me.browser.name == 'Chrome' || me.browser.name == 'Safari') {
        event.returnValue = false;
      } else {
        return false;
      }
      break;
    case 9:
      return true;
      break;
    default:
      if (me.mType == 'date' || me.mType == 'currency' || me.mType == 'percentage' || me.validate == 'Real' || me.validate == 'Int') {
        if ((48 <= pressKey && pressKey <= 57) || (pressKey == 109 || pressKey == 190 || pressKey == 188 || pressKey == 189) || (96 <= pressKey && pressKey <= 111)) {
          return true;
        } else {
          return false;
        }
      }
      break;
  }
  return true;
}
keypress
Code: Select all
function(event) {
  if (me.element.readOnly) {
    return true;
  }
  if ((me.mType != 'currency' && me.mType != 'percentage' && me.mType != 'date') && (me.element.value.length > me.element.maxLength - 1)) {
    return true;
  }
  if (me.validate == 'Any' && me.mask == '') return true;
  var keyCode = (window.event) ? window.event.keyCode : event.which;
  if (navigator.userAgent.indexOf('MSIE') != -1) {
    if (keyCode == 0) return true;
  }
  switch (keyCode) {
    case 9:
    case 13:
      return true;
      break;
  }
  var swShiftKey = ((me.mType == 'currency') || (me.mType == 'percentage') || (me.validate == 'Real') || (me.validate == 'Int')) ? false : true;
  if (window.event) {
    if (window.event.altKey) {
      return true;
    }
    if (window.event.ctrlKey) {
      return true;
    }
  } else {
    if (event.altKey) {
      return true;
    }
    if (event.ctrlKey) {
      return true;
    }
  }
  me.checkBrowser();
  if ((me.browser.name == 'Firefox') && (keyCode == 8) && (me.validate != 'NodeName')) {
    if (me.browser.name == 'Chrome' || me.browser.name == 'Safari') {
      event.returnValue = false;
    } else {
      return false;
    }
  } else {
    var pressKey = (window.event) ? window.event.keyCode : event.which;
    keyValid = true;
    updateOnChange = true;
    switch (me.validate) {
      case 'Any':
        keyValid = true;
        break;
      case 'Int':
        patron = /[0-9\-]/;
        key = String.fromCharCode(pressKey);
        keyValid = patron.test(key);
        break;
      case 'Real':
        if (typeof me.comma_separator != 'undefined') {
          patron = /[0-9\-]/;
        } else {
          patron = /[0-9,\.]/;
        }
        key = String.fromCharCode(pressKey);
        keyValid = patron.test(key);
        keyValid = keyValid || (pressKey == 45);
        if (typeof me.comma_separator != 'undefined') {
          if (me.comma_separator == '.') {
            if (me.element.value.indexOf('.') == -1) {
              keyValid = keyValid || (pressKey == 46);
            }
          } else {
            if (me.element.value.indexOf(',') == -1) {
              keyValid = keyValid || (pressKey == 44);
            }
          }
        }
        break;
      case 'Alpha':
        patron = /[a-zA-Z]/;
        key = String.fromCharCode(pressKey);
        keyValid = patron.test(key);
        break;
      case 'AlphaNum':
        patron = /[a-zA-Z0-9\sáéíóúäëïöüñçÇÑ�É�ÓÚÄË�ÖÜ]/;
        key = String.fromCharCode(pressKey);
        keyValid = patron.test(key);
        break;
      case 'NodeName':
      case 'Login':
        updateOnChange = false;
        if (me.getCursorPos() == 0) {
          if ((pressKey >= 48) && (pressKey <= 57)) {
            keyValid = false;
            break;
          }
        }
        if ((keyCode == 8) && (me.validate == 'NodeName')) {
          keyValid = true;
        } else {
          var k = new leimnud.module.validator({
            valid: ['Login'],
            key: (window.event) ? window.event : event,
            lang: (typeof(me.language) !== 'undefined') ? me.language : "en"
          });
          keyValid = k.result();
        }
        break;
      default:
        var k = new leimnud.module.validator({
          valid: [me.validate],
          key: (window.event) ? window.event : event,
          lang: (typeof(me.language) !== 'undefined') ? me.language : "en"
        });
        keyValid = k.result();
        break;
    }
    if (keyValid) {
      if (me.mask == "" && (me.validate == 'Real' || me.validate == 'Int') && me.mType == 'text') {
        if (key == '-') {
          currentValue = me.element.value;
          if (currentValue.charAt(0) == '-') {
            currentValue = currentValue.substring(1, currentValue.length);
            me.element.value = currentValue;
          } else {
            me.element.value = '-' + currentValue;
          }
        }
      }
      if ((me.validate == "Login" || me.validate == "NodeName") && me.mask == "") {
        return true;
      }
      if (pressKey == 46) {
        me.applyMask(256);
      } else {
        me.applyMask(pressKey);
      }
      if (updateOnChange) {
        me.sendOnChange();
      }
    }
    if (me.browser.name == 'Firefox') {
      if (keyCode == 0) return true;
    }
    if (me.browser.name == 'Chrome' || me.browser.name == 'Safari') {
      event.returnValue = false;
    } else {
      return false;
    }
  }
}
Thanks for your help
pass json array into grid

Oops, I forgot to increment the counter. It should[…]

I managed to connect rest api via php (curl: <[…]

Stop submit from javacript

Thank you will do like that

By the way 65535 is the max size of the varchar an[…]