I have a required Dexterity choice field with a list of possible values:
Please choose one:
Choice A
Choice B
Choice C
I would like the first element that says, "Please choose one:" as a choice with no value so that it forces the user to choose either Choice A, B or C. How can I make the first element a non-value?
Also make sure you have declared the form XML namespace in the file's top-level tag if it's not there already: xmlns:form="http://namespaces.plone.org/supermodel/form"
Thank you. Yes, I do have the form declaration at the top.
Doing what you have suggested, the list now shows Choice A by default. Adding a blank choice below does not help either because Plone sees it as a valid entry and not as a non-value entry:
If so, based on it, this is what I did:
Added the following in file called policy.py in my.product/src/my/product/policy.py
"""Module where all interfaces, events and exceptions live."""
from ncdhhscontenttype.ncssinfo import _
from zope import schema
from zope.interface import Interface
from zope.publisher.interfaces.browser import IDefaultBrowserLayer
from plone.supermodel import model
from Acquisition import aq_inner
from plone import api
from Products.Five import BrowserView
from z3c.form import validator
from zope.interface import Invalid
class IMyProductLayer(IDefaultBrowserLayer):
"""Marker interface that defines a browser layer."""
class CustomValidator(validator.SimpleFieldValidator):
def validate(self, value):
super(CustomValidator, self).validate(value)
if value:
if ['Please choose one:']:
raise Invalid(u'Value is not valid')
In my schema model file, policy.xml file, I called it using the following:
SupermodelParseError: error parsing attribute name
It is referring to the line that has the form:validator statement in my policy.xml file. I am sure I am missing something. Any help would be most appreciated. Thank you.
while I'm not quite answering to the original question, I'd just say that it should be possible with file based Python code since it can be done TTW with Ambidexterity
Validator
if value not in ("1","2","3"):
error_message = "pick a value"
Vocabulary
vocabulary = [("Pick a value",""),("title for value 1","1"),("title for value 2","2"),("title for value 3","3")]
Thank you so much for the codes. So in my case, could I just define NOVALUE such as: @implementer(IVocabularyFactory)
class YesNoAllVocabulary(object):