@@ -164,65 +164,62 @@ def __init__(
164
164
)
165
165
166
166
self .first_name_field = views .TTextField (
167
- on_change = self .on_fname_changed ,
168
167
label = "First Name" ,
169
168
hint = self .invoicing_contact .first_name ,
170
169
initial_value = self .invoicing_contact .first_name ,
171
170
)
172
171
173
172
self .last_name_field = views .TTextField (
174
- on_change = self .on_lname_changed ,
175
173
label = "Last Name" ,
176
174
hint = self .invoicing_contact .last_name ,
177
175
initial_value = self .invoicing_contact .last_name ,
178
176
)
179
177
self .company_field = views .TTextField (
180
- on_change = self .on_company_changed ,
181
178
label = "Company" ,
182
179
hint = self .invoicing_contact .company ,
183
180
initial_value = self .invoicing_contact .company ,
184
181
)
185
182
self .email_field = views .TTextField (
186
- on_change = self .on_email_changed ,
187
183
label = "Email" ,
188
184
hint = self .invoicing_contact .email ,
189
185
initial_value = self .invoicing_contact .email ,
190
186
)
191
187
192
188
self .street_field = views .TTextField (
193
- on_change = self .on_street_changed ,
194
189
label = "Street" ,
195
190
hint = self .invoicing_contact .address .street ,
196
191
initial_value = self .invoicing_contact .address .street ,
197
192
width = half_of_pop_up_width ,
198
193
)
199
194
self .street_num_field = views .TTextField (
200
- on_change = self .on_street_num_changed ,
201
195
label = "Street No." ,
202
196
hint = self .invoicing_contact .address .number ,
203
197
initial_value = self .invoicing_contact .address .number ,
204
198
width = half_of_pop_up_width ,
205
199
)
206
200
self .postal_code_field = views .TTextField (
207
- on_change = self .on_postal_code_changed ,
208
201
label = "Postal code" ,
209
202
hint = self .invoicing_contact .address .postal_code ,
210
203
initial_value = self .invoicing_contact .address .postal_code ,
211
204
width = half_of_pop_up_width ,
212
205
)
213
206
self .city_field = views .TTextField (
214
- on_change = self .on_city_changed ,
215
207
label = "City" ,
216
208
hint = self .invoicing_contact .address .city ,
217
209
initial_value = self .invoicing_contact .address .city ,
218
210
width = half_of_pop_up_width ,
219
211
)
220
212
self .country_field = views .TTextField (
221
- on_change = self .on_country_changed ,
222
213
label = "Country" ,
223
214
hint = self .invoicing_contact .address .country ,
224
215
initial_value = self .invoicing_contact .address .country ,
225
216
)
217
+ self .client_name_field = views .TTextField (
218
+ label = "Client's name" ,
219
+ hint = self .client .name ,
220
+ initial_value = self .client .name ,
221
+ )
222
+
226
223
self .contacts_dropdown = views .TDropDown (
227
224
on_change = self .on_contact_selected ,
228
225
label = "Select contact" ,
@@ -241,12 +238,7 @@ def __init__(
241
238
views .Spacer (xs_space = True ),
242
239
self .form_error_field ,
243
240
views .Spacer (xs_space = True ),
244
- views .TTextField (
245
- on_change = self .on_client_name_changed ,
246
- label = "Client's name" ,
247
- hint = self .client .name ,
248
- initial_value = self .client .name ,
249
- ),
241
+ self .client_name_field ,
250
242
views .Spacer (xs_space = True ),
251
243
views .THeading (
252
244
title = "Invoicing Contact" ,
@@ -282,16 +274,6 @@ def __init__(
282
274
],
283
275
)
284
276
super ().__init__ (dialog = dialog , dialog_controller = dialog_controller )
285
- self .title = ""
286
- self .fname = ""
287
- self .lname = ""
288
- self .company = ""
289
- self .email = ""
290
- self .street = ""
291
- self .street_num = ""
292
- self .postal_code = ""
293
- self .city = ""
294
- self .country = ""
295
277
self .on_submit_callback = on_submit
296
278
self .on_error_callback = on_error
297
279
self .form_error = ""
@@ -305,20 +287,18 @@ def get_contacts_as_list(self):
305
287
contacts_list .append (item )
306
288
return contacts_list
307
289
308
- def get_contact_dropdown_item (self , key ):
290
+ def get_contact_dropdown_item (self , contact_id ):
309
291
"""appends an id to the contact name for dropdown options"""
310
- if key is not None and key in self .contacts_as_map :
311
- return f"# { key } { self .contacts_as_map [key ].name } "
292
+ if contact_id is not None and contact_id in self .contacts_as_map :
293
+ return f"{ contact_id } . { self .contacts_as_map [contact_id ].name } "
312
294
return ""
313
295
314
296
def on_contact_selected (self , e ):
315
297
# parse selected value to extract id
316
298
selected = e .control .value
317
299
id = ""
318
300
for c in selected :
319
- if c == "#" :
320
- continue
321
- if c == " " :
301
+ if c == "." :
322
302
break
323
303
id = id + c
324
304
if int (id ) in self .contacts_as_map :
@@ -343,86 +323,59 @@ def toggle_form_error(self):
343
323
self .form_error_field .visible = True if self .form_error else False
344
324
self .dialog .update ()
345
325
346
- def on_client_name_changed (self , e ):
347
- self .title = e .control .value
348
-
349
- def on_fname_changed (self , e ):
350
- self .fname = e .control .value
351
-
352
- def on_lname_changed (self , e ):
353
- self .lname = e .control .value
354
-
355
- def on_company_changed (self , e ):
356
- self .company = e .control .value
357
-
358
- def on_email_changed (self , e ):
359
- self .email = e .control .value
360
-
361
- def on_street_changed (self , e ):
362
- self .street = e .control .value
363
-
364
- def on_street_num_changed (self , e ):
365
- self .street_num = e .control .value
366
-
367
- def on_postal_code_changed (self , e ):
368
- self .postal_code = e .control .value
369
-
370
- def on_city_changed (self , e ):
371
- self .city = e .control .value
372
-
373
- def on_country_changed (self , e ):
374
- self .country = e .control .value
375
-
376
326
def on_submit_btn_clicked (self , e ):
377
327
"""validates the form and calls the on_submit callback"""
378
328
self .form_error = ""
379
329
self .toggle_form_error ()
380
330
331
+ # get values from fields
332
+ client_name = self .client_name_field .value .strip ()
333
+ first_name = self .first_name_field .value .strip ()
334
+ last_name = self .last_name_field .value .strip ()
335
+ company = self .company_field .value .strip ()
336
+ email = self .email_field .value .strip ()
337
+ street = self .street_field .value .strip ()
338
+ street_num = self .street_num_field .value .strip ()
339
+ postal_code = self .postal_code_field .value .strip ()
340
+ city = self .city_field .value .strip ()
341
+ country = self .country_field .value .strip ()
342
+
381
343
self .client .name = (
382
- self . title . strip () if self . title . strip () else self .client .name
344
+ client_name if client_name else self .client .name
383
345
)
384
346
self .invoicing_contact .first_name = (
385
- self .fname .strip ()
386
- if self .fname .strip ()
387
- else self .invoicing_contact .first_name
347
+ first_name if first_name else self .invoicing_contact .first_name
388
348
)
389
349
self .invoicing_contact .last_name = (
390
- self .lname .strip ()
391
- if self .lname .strip ()
350
+ last_name if last_name
392
351
else self .invoicing_contact .last_name
393
352
)
394
353
self .invoicing_contact .company = (
395
- self .company .strip ()
396
- if self .company .strip ()
354
+ company if company
397
355
else self .invoicing_contact .company
398
356
)
399
357
self .invoicing_contact .email = (
400
- self . email . strip () if self . email . strip () else self .invoicing_contact .email
358
+ email if email else self .invoicing_contact .email
401
359
)
402
360
self .address .street = (
403
- self .street .strip ()
404
- if self .street .strip ()
361
+ street if street
405
362
else self .invoicing_contact .address .street
406
363
)
407
364
408
365
self .address .number = (
409
- self .street_num .strip ()
410
- if self .street_num .strip ()
366
+ street_num if street_num
411
367
else self .invoicing_contact .address .number
412
368
)
413
369
self .address .postal_code = (
414
- self .postal_code .strip ()
415
- if self .postal_code .strip ()
370
+ postal_code if postal_code
416
371
else self .invoicing_contact .address .postal_code
417
372
)
418
373
self .address .city = (
419
- self .city .strip ()
420
- if self .city .strip ()
374
+ city if city
421
375
else self .invoicing_contact .address .city
422
376
)
423
377
self .address .country = (
424
- self .country .strip ()
425
- if self .country .strip ()
378
+ country if country
426
379
else self .invoicing_contact .address .country
427
380
)
428
381
self .invoicing_contact .address = self .address
0 commit comments