function validateIdOnBlur()

in script.js [278:315]


  function validateIdOnBlur() {
    if (!selectedMgId || !currentData) return;

    const newId = mgIdInput.value.trim();

    // Check for empty ID
    if (!newId) {
      alert('ID cannot be empty');

      // Find the management group with the original ID (it will now have the selectedMgId value)
      const currentMg = currentData.management_groups.find(mg => mg.id === selectedMgId);
      if (currentMg) {
        mgIdInput.value = currentMg.id;
      }
      return;
    }

    // Check if ID exists elsewhere in the data model
    if (currentData.management_groups.some(mg => mg.id === newId && mg.id !== selectedMgId)) {
      alert('A management group with this ID already exists');

      // Find the management group with the original ID
      const currentMg = currentData.management_groups.find(mg => mg.id === selectedMgId);
      if (currentMg) {
        mgIdInput.value = currentMg.id;
      }

      // Reset the tree view to reflect the original ID
      renderManagementGroups();

      // Reselect the node with the right ID
      selectManagementGroup(selectedMgId);
      return;
    }

    // No need to update the tree view again if validation passes,
    // as we've been updating it in real-time
  }