Skip to content

Commit 18cc092

Browse files
committed
Skipping column-less mapped elements
1 parent 76805d5 commit 18cc092

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

examples/journal_internal.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,21 @@
7575
# Requery the data since we made changes to the sort order
7676
frm['Journal'].requery()
7777

78-
# To edit-protect a Calendar button (or any button), call map_elment()
78+
# ------------------------------------------
79+
# How to Edit Protect your sg.CalendarButton
80+
# ------------------------------------------
81+
82+
# The sg.CalendarButton was not auto-mapped during Form creation.
83+
# We need to do it manually, using `frm.map_element`.
84+
# Typically, to manually map an sg.Input, you would pass the sg.Element, DataSet, and column it refers to,
85+
# but when edit-protecting a Calendar button (or any button), pass None as the column.
86+
7987
frm.map_element(win['datepicker'], frm['Journal'], column=None)
8088
# ['Key of Button'] ^ must be None
81-
frm.edit_protect() # disable edit-protect to start
89+
90+
# By default, action() includes an edit_protect() call, that disables edits in the window.
91+
# You can toggle it off with:
92+
frm.edit_protect() # toggle on/off
8293

8394
# ---------
8495
# MAIN LOOP
@@ -108,4 +119,5 @@
108119
- using the label keyword argument to Form.record() to define a custom label
109120
- using Tables as Form.selector() element types
110121
- changing the sort order of database dataset
111-
"""
122+
- Edit-Protecting a sg.CalendarButton
123+
"""

pysimplesql/pysimplesql.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,10 @@ def records_changed(self, column: str = None, recursive=True) -> bool:
652652
dirty = False
653653
# First check the current record to see if it's dirty
654654
for mapped in self.frm.element_map:
655+
# skip mapped items with no column
656+
if mapped.column is None:
657+
continue
658+
655659
# Compare the DB version to the GUI version
656660
if mapped.table == self.table:
657661
# if passed custom column name
@@ -1220,6 +1224,10 @@ def save_record(self, display_message: bool = True, update_elements: bool = True
12201224

12211225
# Propagate GUI data back to the stored current_row
12221226
for mapped in self.frm.element_map:
1227+
# skip mapped items with no column
1228+
if mapped.column is None:
1229+
continue
1230+
12231231
if mapped.dataset == self:
12241232

12251233
# convert the data into the correct data type using the domain in ColumnInfo
@@ -2380,15 +2388,17 @@ def update_elements(self, target_data_key: str = None, edit_protect_only: bool =
23802388
# Render GUI Elements
23812389
# d= dictionary (the element map dictionary)
23822390
for mapped in self.element_map:
2391+
# if a column-less element is added
2392+
if mapped.column is None:
2393+
continue
2394+
23832395
# If the optional target_data_key parameter was passed, we will only update elements bound to that table
23842396
if target_data_key is not None:
23852397
if mapped.table != self[target_data_key].table:
23862398
continue
23872399

23882400
# skip updating this element if requested
23892401
if mapped.element in omit_elements: continue
2390-
# if a column-less element is added
2391-
if mapped.column is None: continue
23922402

23932403
# Show the Required Record marker if the column has notnull set and this is a virtual row
23942404
marker_key = mapped.element.key + ':marker'

0 commit comments

Comments
 (0)