Ugh, just realized, right from the online book: " Note that when multiple=True, IS_IN_SET will accept zero or more values, i.e. it will accept the field when nothing has been selected. "
How can I have multiple=true AND require the field? Is that possible? David TheSweetlink wrote: > Thank you Massimo, > > The expected behavior is for the 'list:string' field to be a required > field in order for the form to pass validation. > > It is currently a jquery multi-select checkbox dropdown created from > an IS_IN_SET(...zero=None) validator on the same field (which works > perfectly to my knowledge). > > I'm fairly certain there is a simple way to accomplish what I want to > do but I'm not seeing it. > > The idea is to have a custom error message like 'Please select one or > more...bloggittyblahblah'. > > I have a validator in the form which works great for an empty string, > sadly though my list:select will submit no matter what I do whether > there are options selected or none selected. > > How can I implement something like IS_NOT_EMPTY() to require the field > have a value to pass validation with a 'list:string' field? > > David > > On Oct 23, 6:58 pm, Massimo Di Pierro <[email protected]> > wrote: > > Thanks for the reminder. What is the expected behavior? 'list:string' > > only accepts strings that are not empty. Are you trying to have at > > least one item in the list? > > We do not have a validator to do that but can make one: > > > > class IS_LIST_SIZE(Validator): > > > > def __init__(self, min=0,max=10,error_message='not in range'): > > self.min = min > > self.max=max > > self.error_message = error_message > > > > def __call__(self, value): > > ivalue = value > > if not isinstance(value, list): > > ivalue = [ivalue] > > if not self.min<=len(ivalue)<=self.max: > > return (ivalue, self.error_message) > > return (ivalue, None) > > > > On Oct 23, 5:37 pm, TheSweetlink <[email protected]> wrote: > > > > > I don't wish to irritate rather just curious to know if anyone else > > > can replicate this. > > > > > A SQLFORM.factory with an empty field of type='list:string' is > > > submitting as passed when an IS_NOT_EMPTY() validator is used in any > > > and every way possible. > > > > > The very same .factory has a field type string where the same exact > > > validation works as it should. Why should my list:string not work the > > > same way? > > > > > Thank you in advance for your time. > > > > > David > > > >

