Re: Indicating required fields to user?

2006-06-15 Thread Bryan Lewis
I checked the wiki.  The basic technique is already there, at the bottom
of this page:
http://wiki.apache.org/tapestry/CheckingForRequiredValidator

I learned that the code could be simplified.  My isRequired() method --
left over from an earlier Tapestry version -- wasn't needed.  The
writeAttributes() method boils down to:

  if (isInError()) {
  writer.attribute("class", "error");
  }
  else if (component.isRequired()) {
  writer.attribute("class", "required-field");
  }






Andreas Bulling wrote:

>Nice one - thanks for that! ;)
>Perhaps that's something for the Wiki...
>
>Andreas
>
>On 14. Jun 2006 - 17:18:28, Bryan Lewis wrote:
>| Here's what's been working well for us.  Our custom ValidationDelegate
>| extends Tapestry's ValidationDelegate and overrides the
>| writeAttributes() method, which is documented as "Does nothing. Override
>| in a subclass to decorate fields."  We emit a
>| class="required-field" attribute.  It's up to the app's stylesheet to
>| define the appearance.
>| 
>|public void writeAttributes(IMarkupWriter writer,
>| IRequestCycle cycle,
>| IFormComponent component,
>| IValidator validator)
>| {
>| if (isInError()) {
>| writer.attribute("class", "error");
>| }
>| else if (isRequired(component)) {
>| writer.attribute("class", "required-field");
>| }
>| }
>| 
>| /** Returns true if the component has a Required validator. */
>| public boolean isRequired(IFormComponent component)
>| {
>| boolean retval = false;
>| 
>| if (component instanceof ValidatableField) {
>| Object validators = ((ValidatableField)
>| component).getValidators();
>| if (validators != null
>| // The docs say getValidators() is "coerced into an Iterator
>| // of Validators", but I get a Collection.  Allow for
>| either.
>| Iterator it = null;
>| if (validators instanceof Iterator) {
>| it = (Iterator) validators;
>| }
>| else if (validators instanceof Collection) {
>| it = ((Collection) validators).iterator();
>| }
>| assert it != null;
>| 
>| while (it.hasNext()) {
>| Validator validator = (Validator) it.next();
>| if (validator.isRequired()) {
>| retval = true;
>| break;
>| }
>| }
>| }
>| }
>| return retval;
>| }
>
>-
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>
>  
>


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Indicating required fields to user?

2006-06-15 Thread Andreas Bulling
Nice one - thanks for that! ;)
Perhaps that's something for the Wiki...

Andreas

On 14. Jun 2006 - 17:18:28, Bryan Lewis wrote:
| Here's what's been working well for us.  Our custom ValidationDelegate
| extends Tapestry's ValidationDelegate and overrides the
| writeAttributes() method, which is documented as "Does nothing. Override
| in a subclass to decorate fields."  We emit a
| class="required-field" attribute.  It's up to the app's stylesheet to
| define the appearance.
| 
|public void writeAttributes(IMarkupWriter writer,
| IRequestCycle cycle,
| IFormComponent component,
| IValidator validator)
| {
| if (isInError()) {
| writer.attribute("class", "error");
| }
| else if (isRequired(component)) {
| writer.attribute("class", "required-field");
| }
| }
| 
| /** Returns true if the component has a Required validator. */
| public boolean isRequired(IFormComponent component)
| {
| boolean retval = false;
| 
| if (component instanceof ValidatableField) {
| Object validators = ((ValidatableField)
| component).getValidators();
| if (validators != null
| // The docs say getValidators() is "coerced into an Iterator
| // of Validators", but I get a Collection.  Allow for
| either.
| Iterator it = null;
| if (validators instanceof Iterator) {
| it = (Iterator) validators;
| }
| else if (validators instanceof Collection) {
| it = ((Collection) validators).iterator();
| }
| assert it != null;
| 
| while (it.hasNext()) {
| Validator validator = (Validator) it.next();
| if (validator.isRequired()) {
| retval = true;
| break;
| }
| }
| }
| }
| return retval;
| }

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Indicating required fields to user?

2006-06-14 Thread Bryan Lewis
Here's what's been working well for us.  Our custom ValidationDelegate
extends Tapestry's ValidationDelegate and overrides the
writeAttributes() method, which is documented as "Does nothing. Override
in a subclass to decorate fields."  We emit a
class="required-field" attribute.  It's up to the app's stylesheet to
define the appearance.

   public void writeAttributes(IMarkupWriter writer,
IRequestCycle cycle,
IFormComponent component,
IValidator validator)
{
if (isInError()) {
writer.attribute("class", "error");
}
else if (isRequired(component)) {
writer.attribute("class", "required-field");
}
}

/** Returns true if the component has a Required validator. */
public boolean isRequired(IFormComponent component)
{
boolean retval = false;

if (component instanceof ValidatableField) {
Object validators = ((ValidatableField)
component).getValidators();
if (validators != null
// The docs say getValidators() is "coerced into an Iterator
// of Validators", but I get a Collection.  Allow for
either.
Iterator it = null;
if (validators instanceof Iterator) {
it = (Iterator) validators;
}
else if (validators instanceof Collection) {
it = ((Collection) validators).iterator();
}
assert it != null;

while (it.hasNext()) {
Validator validator = (Validator) it.next();
if (validator.isRequired()) {
retval = true;
break;
}
}
}
}
return retval;
}



Phillip Rhodes wrote:

>I am using tapestry validation successfully for required fields.  All
>works well.  However, I need to display a required indicator to the user
>so that they know before submitting the form that these fields are
>required.  Currently, users must submit the form to enable the "required"
>decorations.
>
>It would be nice if I could toggle on the validation decorations in the
>form on the initial presentation of the form to the user, so they don't
>have to guess which fields are required when they are filling out the form
>the first time.
>
>any pointers would be appreciated.
>
>
>
>
>
>-
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>
>  
>


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Indicating required fields to user?

2006-06-14 Thread Phillip Rhodes
I am using tapestry validation successfully for required fields.  All
works well.  However, I need to display a required indicator to the user
so that they know before submitting the form that these fields are
required.  Currently, users must submit the form to enable the "required"
decorations.

It would be nice if I could toggle on the validation decorations in the
form on the initial presentation of the form to the user, so they don't
have to guess which fields are required when they are filling out the form
the first time.

any pointers would be appreciated.





-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]