Question

I'm writing a simple content type with Dexterity to manage customers, beside the usuals fields, eg name, company, phone... I've also added a Datetime field to store when the first meeting with customers has been held, lets call it 'firstmeeting', which I defined in my interface ICustomers as:

firstmeeting = schema.Datetime(
        title=_(u"First Meeting"),
        required=False,
    )

Now, I notice that when I saved a new Customer document the firstmeeting field has been filled with the current date even if I don't set any date in the form, which is not what I want because no meeting with the customer has been held yet. So I'd like to know how to set a None value for this field so nothing will be displayed.

I've been trying to use a custom class has explained by Martin Aspeli in http://plone.org/products/dexterity/documentation/manual/developer-manual/advanced/classes but I don't know how to check the user input and set None value if nothing was typed in.

Thanks

Was it helpful?

Solution 2

I found out what was happening in my code.

Actually the problem was in the template view.pt where I used toLocalizedTime() function, which was converting the None value to the current date, so I added a tal:condition to print the date value.

<span id="form-widgets-firstmeeting" class="datetime-widget datetime-field"
      tal:condition="context/firstmeeting"
      tal:content="python:context.toLocalizedTime(context.firstmeeting)" />

OTHER TIPS

Have you tried default=None?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top