Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8750769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:55:28+00:00 2026-06-13T12:55:28+00:00

I’m using a form where I want to have the required field missing error

  • 0

I’m using a form where I want to have the required field missing error on many fields depending on the value of one other field.

The use case: the use have to choose between two shipping mode (postale or print). if postale is choosen but fields about address has not been filled I want to raise the error.

Here is some code

class ILivraisonForm(interface.Interface):
    livraison = schema.Choice(title=_(u"Mode de livraison"),
                              vocabulary=vocabulary.livraison)

    livraison_civility = schema.Choice(title=_(u"Civility (livraison)"),
                                       vocabulary=userdata.gender_vocabulary,
                                       required=False)
    livraison_name = schema.TextLine(title=_(u"Name (livraison)"),
                                        required=False)
    livraison_firstname = schema.TextLine(title=_(u"Firstname (livraison)"),
                                        required=False)
    livraison_add1 = schema.TextLine(title=_(u"Address line 1 (livraison)"),
                                        required=False)
    livraison_add2 = schema.TextLine(title=_(u"Address line 2 (livraison)"),
                                        required=False)
    livraison_pc = schema.TextLine(title=_(u"Postal code (livraison)"),
                                        required=False)
    livraison_city = schema.TextLine(title=_(u"City (livraison)"),
                                        required=False)

    livraison_phone = schema.TextLine(title=_(u"Phone"),
                                        required=False)

    accepted = schema.Bool(title=_(u"Accept CGV"),
                           description=_(u"Click here to read the CGV"),
                           required=True)


class LivraisonForm(form.Form):
    fields = field.Fields(ILivraisonForm)

    @button.buttonAndHandler(_(u"Valider"))
    def handleApply(self, action):
        data, errors = self.extractData()
        message = IStatusMessage(self.request)
        if errors:
            self.status = _(u"Please fix errors")
            return
        if not data['accepted']:
            self.status = _(u'You must accept')
            raise WidgetActionExecutionError('accepted',
                                     interface.Invalid(_(u'You must accept')))

        if data['livraison'] == 'mail' \
          and ( not data['livraison_name'] or not data['livraison_firstname'] \
          or not data['livraison_add1'] or not data['livraison_pc'] \
          or not data['livraison_city']):
            self.status = _(u'You must add your postal address')
            raise ???
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:55:29+00:00Added an answer on June 13, 2026 at 12:55 pm

    You don’t need to raise anything; just add a return instead of a raise right where you are.

    In addition, you can set error messages on individual widgets in an action handler, provided you create a zope.schema.ValidationError subclass:

    from zope.schema import ValidationError
    
    class AddressMissing(ValidationError):
        __doc__ = _(u'error_noaddress', u'Please provide an address')
    

    and then in the handler:

    from z3c.form.interfaces import IErrorViewSnippet
    from zope import component
    
    def handleApply(self, action):
        # ....
    
        widget = self.widgets['livraison_add1']
        error = component.getMultiAdapter(
            (AddressMissing(), self.request, widget, widget.field,
             self, self.context), interfaces.IErrorViewSnippet)
        error.update()
        widget.error = error
    

    You can do this for all affected widgets.

    Alternatively, you can have this handled using an invariant:

    from zope.interface import invariant, Invalid
    
    class ILivraisonForm(interface.Interface):
        # ....
    
        @invariant
        def validatePostalAddress(data):
            if data.livraison. != 'mail':
                return
            for field in ('name', 'firstname', 'add1', 'pc', 'city'):
                if not data['livraison_' + field]:
                    raise Invalid(_(u'error_noaddress', u'Please provide an address'))
    

    and the error will be set when you call self.extractData().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I have a text area in my form which accepts all possible characters from
I have thousands of HTML files to process using Groovy/Java and I need to
I'm making a simple page using Google Maps API 3. My first. One marker
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.