Page 1 of 1

Grid Datetime control on change

Posted: Tue May 16, 2017 12:47 pm
by sgkalluri
Hello everyone,

I would like to know if there is a change in any cell of a grid. I use the following javascript code for this...

$("#AnyGrid").on("change", ":input", function()
{
.... code ....
});

This seems to work for drop downs and text boxes of the grid. However, it does not work for datetime controls in the grid.

What could be the related event handler for datetime controls in a grid?

Best wishes,
SGK

Re: Grid Datetime control on change

Posted: Tue May 16, 2017 10:08 pm
by amosbatto
If is recommended to use this code for change events in grids:
Code: Select all
function gridChangeHandler(fieldId, newVal, oldVal) {
  //if a value is changed inside the "mygrid" grid:
  if (fieldId.search(/^\[mygrid\]/) == 0) {
    //add code here
  }
}
$("form").setOnchange( gridChangeHandler );
If you need to check for changes in the datatime field in the grid:
Code: Select all
function gridChangeHandler(fieldId, newVal, oldVal) {
  //if a value is changed inside the datetime field in the "mygrid" grid:
  if (fieldId.search(/^\[mygrid\]\[\d+\]\[mydatetime\]$/) == 0) {
    //add code here
  }
}
$("form").setOnchange( gridChangeHandler );
See: http://wiki.processmaker.com/3.0/Grid_C ... s_in_grids

Re: Grid Datetime control on change

Posted: Wed May 24, 2017 10:17 pm
by sgkalluri
Thank you very much once again, Amos! The code worked.

Do you think the same code could be used in the following situation...

- The concerned grid is in a sub-form of the main form
- I would like to place the gridChangeHandler function in the main form as the code to be executed needs to change some fields in the main form "on change" of the concerned grid in the sub-form

Re: Grid Datetime control on change

Posted: Fri May 26, 2017 12:16 am
by amosbatto
sgkalluri wrote:- The concerned grid is in a sub-form of the main form
- I would like to place the gridChangeHandler function in the main form as the code to be executed needs to change some fields in the main form "on change" of the concerned grid in the sub-form
The form.setOnchange() doesn't work with subforms. The only workaround I know is to use code like this in the master form:
Code: Select all
$("form").change(function(event) {
  var fieldId = event.target.id;
  //the ID will be like "form[gridID][rowNumber][fieldID]"
  var val = event.target.value;
});

Re: Grid Datetime control on change

Posted: Fri May 06, 2022 7:46 am
by kindel
@sgkalluri were you able to do the set on change on datetime variable in grid?