0

I have a document render event listener to catch changes to my list. If I edit the time value of an entry, it will auto update other fields for that entry (such as milliseconds). This works for all records EXCEPT in the case when I add a new record, then go to edit that record. The edit screen freezes upon submit and the console tells me "cannot read field value of undefined". Instead of undefined it should be the time value. Why is my field value undefined?

I've tried removing the if conditional (this results in no auto updates at all).

$(document).on('knack-records-render.view_2320', function(event, scene, records) {

  $(document).on('knack-record-update.view_2321', function(event, view, updatedRecord) {
    // Filter the initially loaded records for the one with the same ID as the updated one
    var recordBeforeUpdate = records.filter(recordFromRenderEvent => {
      return recordFromRenderEvent.id === updatedRecord.id;
    })[0];

    if (updatedRecord.field_1876 !== recordBeforeUpdate.field_1876) {
var recordId = updatedRecord.id

//then i calculate milliseconds and use ajax call to send data

When I add new entry (using $(document).on('knack-record-create.view_2323') then edit this entry it says field_1876 is undefined and does not do the auto update! updatedRecord.field_1876 should be newly put time value and recordBeforeUpdate.field_1876 should be time value before edit. Neither should be undefined. If I refresh page after adding entry then it works. I want it to work without a page refresh.

VikingBarrister
  • 109
  • 3
  • 5
  • 1
    Hard to help when we have no idea what API you are using to generate those events or what `records` or `updatedRecord` look like – charlietfl Jul 18 '19 at 14:29
  • Sounds like the component that is raising the `knack-recorders-render` / `-update` events isn't using **event delegation** so only affects the elements that exist at the time of initialisation. As above, can't be sure without knowing more details. Have a read of: https://stackoverflow.com/questions/203198/event-binding-on-dynamically-created-elements – freedomn-m Jul 18 '19 at 14:55
  • what do records look like? – VikingBarrister Jul 18 '19 at 15:14

0 Answers0