search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

PHP Shift planning

Asked by Anonymous
6 months ago.

there is error while selecting location in shift planning PHP

uncaught type error: cannot read properties of undefined(reading: ‘id’)

Answer posted by Dan Letecky [DayPilot]
6 months ago.

This error has been fixed recently. Please make sure that you have the latest version (from May 21, 2024):

If the problem persists, please let me know.

Comment posted by Rohit
5 months ago.

still the same problem persisting

Uncaught TypeError: Cannot read properties of undefined (reading 'id')

at Object.activate (phpshiftplanning/:47:65)

at HTMLSelectElement.<anonymous> (phpshiftplanning/:68:21)

activate @ phpshiftplanning/:47

(anonymous) @ phpshiftplanning/:68

phpshiftplanning/:44 Uncaught TypeError: Cannot read properties of undefined (reading 'id')

at phpshiftplanning/:44:48

at a (daypilot-all.min.js:32:20294)

at t.onreadystatechange (daypilot-all.min.js:9:19919)

Comment posted by Dan Letecky [DayPilot]
5 months ago.

Does the locations object look like this?

  const locations = {
    list: [],
    find(id) {
      if (!locations.list) {
        return null;
      }
      return locations.list.find(item => item.id === id);
    },
    element: document.querySelector("#locations"),
    activate(location) {
      let item = location;
      if (typeof location !== "object") {
        item = locations.find(location);
      }
      dp.events.list = [];

      dp.rows.load("backend_people.php", (args) => {
        args.data.splice(0, 0, {id: "L" + item.id, name: item.name, type: "location"});
      });

      dp.events.load("backend_assignments.php?location=" + item.id);

    },
    async load() {
      const {data} = await DayPilot.Http.get("backend_locations.php");
      locations.list = data;
      locations.element.innerHTML = '';

      locations.list.forEach((item) => {
        const option = document.createElement("option");
        option.value = item.id;
        option.innerText = item.name;
        locations.element.appendChild(option);
      });

      locations.activate(locations.list[0]);
    },
    init() {
      window.addEventListener("DOMContentLoaded", () => {
        locations.element.addEventListener("change", (ev) => {
          const locationId = parseInt(ev.currentTarget.value);
          locations.activate(locationId);
        });
        locations.load();
      });
    }
  };
Comment posted by Rohit
5 months ago.

Yes but it has

locations.init(); in the end

Comment posted by Dan Letecky [DayPilot]
5 months ago.

Unfortunately, I’m not able to reproduce the problem.

However, it looks like the error is coming from the “change” event handler. I recommend placing a breakpoint there or printing the values to the console to see they are what you expect:

    init() {
      window.addEventListener("DOMContentLoaded", () => {
        locations.element.addEventListener("change", (ev) => {
          const locationId = parseInt(ev.currentTarget.value);

          console.log("change event", ev.currentTarget.value, locationId);

          locations.activate(locationId);
        });
        locations.load();
      });
    }

The locationId should be the number of the selected location.

This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.