From 9808bb3a913fb8380ae31052982a8bff4115cf2c Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Fri, 17 Mar 2017 18:15:54 -0500 Subject: [PATCH] Fix behavior of default email/phone field with empty value --- tailbone/forms/fields.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tailbone/forms/fields.py b/tailbone/forms/fields.py index c052745a..17ea4d45 100644 --- a/tailbone/forms/fields.py +++ b/tailbone/forms/fields.py @@ -72,9 +72,12 @@ class DefaultEmailField(fa.Field): address = self._deserialize() contact = self.parent.model if contact.emails: - email = contact.emails[0] - email.address = address - else: + if address: + email = contact.emails[0] + email.address = address + else: + contact.emails.pop(0) + elif address: email = contact.add_email_address(address) @@ -96,7 +99,10 @@ class DefaultPhoneField(fa.Field): number = self._deserialize() contact = self.parent.model if contact.phones: - phone = contact.phones[0] - phone.number = number - else: + if number: + phone = contact.phones[0] + phone.number = number + else: + contact.phones.pop(0) + elif number: phone = contact.add_phone_number(number)