Thanks DenesL and Massimo,

I think e['hideerror]=True is the solution.

I wasn't sure before but this confirms that the requirements are
checked on the server-side after the post. I thought it might be done
before the post using javascript or ajax.

Cheers, Duane.

On Apr 7, 7:41 am, DenesL <[email protected]> wrote:
> OK, here is one way:
>
> def radio_msg():
>   opts=['english', 'french', 'german']
>   form=SQLFORM.factory(
>     Field('language', 'string',
>       requires = IS_IN_SET(opts),
>       widget = SQLFORM.widgets.radio.widget
>     )
>   )
>   if form.accepts(request):
>     response.flash='ok'
>   elif form.errors:
>     # turn off error msg for all but last radio field
>     for opt in opts[:-1]:
>       form.element('input[type=radio][value=%s]'%opt)
> ['hideerror']=True
>     response.flash='not ok'
>   return dict(form=form)
>
> On Apr 6, 11:14 am, DenesL <[email protected]> wrote:
>
> > The radio elements do not have an id, and even if they did this would
> > turn all messages off, the idea is to leave only one.
>
> > It would be easy with jQuery, something like:
>
> > $("div#language__error").each(function() {$(this).hide();});
> > $("div#language__error").last().show();
>
> > where "language" is the radio field name in this case.
>
> > On Apr 6, 9:18 am, Massimo Di Pierro <[email protected]>
> > wrote:
>
> > > you can do
>
> > > for e in form.elements('input#id'): e['hideerror']=True
>
> > > and matching fields would not display errors.
>
> > > On Apr 6, 4:30 am, DenesL <[email protected]> wrote:
>
> > > > In principle I agree that it looks bad to have the same error pop up
> > > > for each radio field, but the reality is that each option is handled
> > > > as a separate entity even in the HTML code, so I doubt this is an easy
> > > > one to "fix".
>
> > > > It is also a matter of interpretation, to go back to your example, all
> > > > of them would be in error if no particular one was chosen.
>
> > > > On Apr 5, 9:08 pm, bluemoth <[email protected]> wrote:
>
> > > > > Hi,
>
> > > > > I originally thought the FIELDSET might hold the solution but no.
> > > > > Maybe it can be used.
>
> > > > > Otherwise, I think the solution might be to recognise that the radio
> > > > > buttons relate to the same field and treat them as a group. But we
> > > > > still need an appropriate place/target to report the error. This could
> > > > > be after the last input (radio button) or a defined target in the
> > > > > validator e.g., require=IS_NOT_EMPTY(error_target='target')
>
> > > > > It's not an urgent issue. I did some searching and couldn't find the
> > > > > solution. I will want to overcome this later but don't want to
> > > > > implement my own solution if one exists or can be added.
>
> > > > > Cheers, Duane.
>
> > > > > On Apr 6, 12:55 pm, bluemoth <[email protected]> wrote:
>
> > > > > > Thanks DenesL,
>
> > > > > > It was probably the wrong example. I simplified my case but in my 
> > > > > > case
> > > > > > I do expect errors to be reported so I was wanting to group the 
> > > > > > error
> > > > > > messages for the radio buttons into one message.
>
> > > > > > Cheers, Duane.
>
> > > > > > On Apr 6, 10:56 am, DenesL <[email protected]> wrote:
>
> > > > > > > Hello,
>
> > > > > > > to eliminate the possibility of an error message, I would rewrite 
> > > > > > > as:
>
> > > > > > > db.languages.language.default = 'english' # or any other in the 
> > > > > > > list
> > > > > > > db.languages.language.requires = IS_IN_SET(['english', 'french',
> > > > > > > 'german'])
> > > > > > > db.languages.language.widget = SQLFORM.widgets.radio.widget
>
> > > > > > > On Apr 5, 6:32 pm, bluemoth <[email protected]> wrote:
>
> > > > > > > > Hello all,
>
> > > > > > > > If I have the following:
> > > > > > > > db.define_table('languages', Field('language', 'string'))
>
> > > > > > > > db.languages.language.requires = \
> > > > > > > >                 [IS_IN_SET(['english', 'french', 'german']), \
> > > > > > > >                  IS_NOT_EMPTY(error_message='Value required')]
> > > > > > > > db.languages.language.widget = SQLFORM.widgets.radio.widget
>
> > > > > > > > and I render a form that when submitted has no entry, it places 
> > > > > > > > an
> > > > > > > > error message under each radio button.
>
> > > > > > > > Is there a way to present the one error message for the entire 
> > > > > > > > group
> > > > > > > > of radio buttons?
>
> > > > > > > > Thanks for you help.
>
> > > > > > > > Cheers, Duane.
>
>

Reply via email to