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

Moderator: amosbatto

Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.
#825042
Hi all,
I've a strange behavoir with this piece of code (is an example, in production it doesn't show an alert but it set other values for other fields on the same row):
Code: Select all
$("form").setOnchange(modifiedForm);
function modifiedForm(fieldId, newVal, oldVal){
    console.log("fieldId: " + fieldId + " - newVal: " + newVal + " - oldVal: " + oldVal);
    if (oldVal != ''){
        rowID = (fieldId.substring(16,fieldId.length)).substring(0,(fieldId.substring(16,fieldId.length)).indexOf(']'));
        fieldTemp = ((fieldId.substring(16,fieldId.length)).substring(fieldId.substring(16,fieldId.length).indexOf('[')+1));
        field = fieldTemp.substring(0,fieldTemp.length-1);

        if (newVal!=oldVal){
			if (newVal > 500){
				alert("New value>500!");
			}
        }
    }
}
In brief, it works fine when I make changes but when I remove a row the content of fieldId contain the old index row.
Anyone can help me to understand why and how I can resolve it?!?

Thanks!
#825085
I don't understand your question.

Is this what you want to do?
Code: Select all
$("form").setOnchange(modifiedForm);
function modifiedForm(fieldId, newVal, oldVal) {
   //check if changing a particular field in the grid.
   //change myGrid and myField to the IDs of your grid and your grid field.
   var aMatch = fieldId.match(/^\[myGrid\]\[(\d+)\]\[myField\]$/);
   
   if (aMatch && oldVal != '') {
        var rowNo = aMatch[1];

        if (newVal != oldVal) {
             var newValue = parseInt(newVal);

	     if (newValue > 500) {
		 alert("New value in row "+rowNo+" is over 500. Setting to maximum of 500");
                 $("#myGrid").setValue(500, rowNo, 3); //change 3 to the column number of grid that you want to change
	     }
        }
    }
}
#825091
Thanks for your reply,
no, the problem is that if you add more than one row and you exec the code you will have, modifying the 5th row, rowNo=5.
If you delete one row (from 1 to 4) and try to modiy the new 2nd row you have the same rowNo=5 when I'm expecting rowNo=2.
I hope I was clear.
#825100
You can try using this:
Code: Select all
var formId = $("form").prop("id");
$("#"+formId).change( function(e) {
  var val = e.target.value;
  var aMatch = e.target.id.match( /^form\[clientList\]\[(\d+)\]\[(\w+)\]$/ );
  
  if (aMatch) {
    var rowNo = aMatch[1];
    var gridFieldId = aMatch[2];
    alert("Field "+gridFieldId+" in row "+rowNo+" was changed to '"+val+"'");
  }
});
Where "clientList" is the ID of the grid.

I don't know how to get the previous value, but this will get you the row number and ID of the field in the grid.
Task doesnt have any users.

Amosbatto: One more thing if you can help me with.[…]

Just guide me to implement this?

Hi, I have a text control (rfq_segment) and I wan[…]

Genial!!! gracias. :D i need to translate an[…]